Symfony 4: Using routes, rendering html documents and managing links - symfony

I'm new to Symfony, but I believe I understand how routes and controllers work. I've played with the tutorials on their website and everything was going great. However, I am not able to do some (supposedly) very simple things and I can't find anything useful when googling. To be honest, I'm not even sure I'm using the proper terminology, which makes looking online difficult. Here's what I would like to do:
Use routes to point to files with HTML and display them. As I understand it, these files will be inside the public directory. What's the proper way to point to them from my controller class (see below).
e.g.:
class PageController
{
/**
* #Route("/")
*/
public function homepage()
{
return new Response('location of home.php');
}
}
Similarly, link to CSS and JS from within the HTML. That includes working with CSS frameworks such as Bulma - which is installed in node_modules, outside the public directory. How do I manage that?
In a project without Symfony, my links on the document head look like this:
href="img/favicon.png"
href="node_modules/bulma/css/bulma.css"
href="css/style.css"
How do I manage those now?
How do I apply what I already know about designing websites to Symfony?

normaly you need to return a file "twig", like for exemple: return $this->render('your_file_ruter/locationOfHome.html.twig')

Related

Rails 5 - static index.html in public folder does not display the background image on production

I build a Rails 5 app where the index page is static and inside the public folder.
I have a controller which does this:
render :file => 'public/index.html'
The router routes to:
get 'welcome/index'
root 'welcome#index'
In my inline css I added this:`
background-image: url('images/logo.jpg');
On stackoverflow there are some topics already about not displayed but all answers did not help. Very soon I want to have a simple Responsive Website located in the public folder. So the problem will a bigger one later I guess.
So the question is, how do I turn on the image display/rendering on production. Or do I go a complete wrong way and have to use the asset pipeline?
The reason for this is because of Asset Fingerprinting that happens on production.
In your CSS ->
background-image: image-url('images/logo.jpg');
Change the image to use the scss/sass helper image-url
More information in the docs.

How to import jar file to scene builder with css file? ( css file does't apply )

I have developing custom button control. Code is very simple. I just create MyButton class extend Button class. And I adding css that in same file. like this
public class PrimaryButton extends Button {
public PrimaryButton(){
getStyleClass().add("primary-button");
getStylesheets().add("primarybutton.css");
}
}
My project structure is this.
I made this project file to jar. And I import this jar to scene builder. But css dose not apply. like this. What is wrong?
I think the problem is with in your CSS file path, and when i changed it,into
getStylesheets().add("sample/primarybutton.css");
it worked fine, and this also worked fine
getStylesheets().add("/sample/primarybutton.css");
NOTE: my app architecture is completely identical to yours
here's the complete sample
public class MyButton extends Button {
public MyButton(){
getStylesheets().add("sample/primarybutton.css");
//you can also use this
//getStylesheets().add("/sample/primarybutton.css");
getStyleClass().add("primary-button");
} }
Note : the "primary-button" is a css class in your "primarybutton.css" file
hope this is useful, and solve your problem
The string you pass to the list of stylesheets is treated as a URL. The documentation states:
The URL is a hierarchical URI of the form [scheme:][//authority][path].
If the URL does not have a [scheme:] component, the URL is considered
to be the [path] component only. Any leading '/' character of the
[path] is ignored and the [path] is treated as a path relative to the
root of the application's classpath.
Since both the class and the stylesheet are in the sample package, the URL of the stylesheet relative to the classpath is sample/primarybutton.css, so you could use
getStylesheets().add("sample/primarybutton.css");
If you want to make use of the fact the the stylesheet is in the same package as the class, and make the code more portable (i.e. not hard-code the package name), you can create a complete URL from the current class, and then convert it to a string:
getStylesheets().add(getClass().getResource("primarybutton.css").toExternalForm());
This works because getClass().getResource(...) creates a URL where the resource name, if it doesn't begin with a leading /, is interpreted as being relative to the current class.
I generally prefer the latter approach, though others may not agree.

Adding functionality to a wordpress plugin

This is a simple concept question... If I have a wordpress plugin and I want to write some functions for my own IN ADDITION to what they have already where would I put them in the wordpress file structure?
I cant put them in the original core.php files/directory because they will get wiped out when the plugins are updated right?
#NomikOS - Yeah Sure .. I have a wordpress plugin called BP-Phototag- pretty much an album..Its located in the wp-content/plugins folder. I want to add my own functions...for a specific template in my themes folder. DO i put the functions in the bpa.core.php file in the wp-conten/plugins folder or do I make a new php file that can inherit bpa.core.php functions(which I dont know how to do) and stick them in my template specific folder under wp-content/themes/mytheme folder. Im really not sure how to extend and override it...
If the plugin is class based, you can extend it to override/add methods. You can include the file containing your code inside plugin's directory if you want (it will not deleted after an upgrade) or directly inside plugins dir.
EDIT 1
Sorry, I didn't saw your last comment. Well, my friend, it's time to learn OOP PHP5. I recommend you PHP 5 objects, patterns, and practice. It's for PHP serious coders.
Basically you do
class leon_my_class extends BP_Phototag_class {
function __construct()
{
parent::__construct();
// my code
}
// overriding protected/public method
function BP_Phototag_method()
{
// this code will replace original code
}
// adding method
function my_own_method()
{
}
}

in SpringSource Tool Suite, where can I edit the themes?

I've been asked to theme a site for a team (just a few hours they said), but they're using Grails with SpringSource tool Suite. I'm not familiar with either.
When I look at the "proper" source, the theme source files don't exist, yet they get served. If I search for the files in the IDE, I get some stuff in .path_to_grails_plugin directory (which is not in source control). If I edit THERE, it picks up my changes, but that doesn't help the team... and I want to point to a NEW theme, not mess up the original one. The Target directory has some of the files, but not all, but isn't that where generated content goes? So where is the REAL source? This feels like the dark arts to me. I am clearly missing some fundamental knowledge about how this works.
I want to add a custom theme (theme-roller-generated), so I created a sub-folder for it in my web-app folder. Then, in my config.groovy file I put:
grails.resources.modules = {
core {
dependsOn 'jquery-ui'
}
// Define reference to custom jQuery UI theme
overrides {
'jquery-theme' {
resource id: 'theme', url: '/css/theme-redo/jquery-ui-1.8.19.custom.css'
}
}
}
That doesn't do anything. It still serves the old css. Help me find the light!
The CSS is stored in the web-app\css and the JavaScript is in the web-app\js directories. However, I high recommend going through some tutorials before moving stuff around by trial and error. Good luck!
I've been running into the same problem. My workaround is to create another Resource module and include the theme there. It's an imperfect solution as the original unwanted theme css is still included - but it works.
ApplicationResources.groovy contains:
modules = {
application {
resource url:'js/application.js'
resource url:'/css/smoothness/jquery-ui-1.8.20.custom.css'
}
}
my.gsp contains:
<r:require modules="jquery, jquery-ui, application" />
ordering may be important..

Flex embed dynamically

In one project, I have several similar applications, they just differ slightly here and there. Like some of the contained icons/images. To help organizing, I see myself [Embed]ing icons in a style like below, however the use of variables in the [Embed] metatag doesn't work.
The below code is contained in a custom component, so I easily should be able to set different icons per application including the component. How do I get around this problem?
public var iconBase:String = "/icons/red/";
[Embed(iconBase + "play.png")] [Bindable] public var icon_play:Class;
[Embed(iconBase + "stop.png")] [Bindable] public var icon_stop:Class;
This should answer your question: Embedding sources dynamically.
Metadata is pre-processed by the compiler, so you can't have any variables in there.
Hope that helps,
Lance
You have quite a few options:
Write a quick code generator to
build the appropriate source files.
Load the icons at runtime, that
way you could change the paths.
Use symlinks to change where the
icon files are retrieved from.
Make an icon library or module and
either load them at compile time or
at runtime.
I think I would just load the images at runtime and change the base path.
One option is to use the ResourceManager and put embed statements in resources files. Different apps could define different resource bundles.
u could use
btn.setStyle(“icon”,iconSymbol);
it can help

Resources