Hi all im working on zf2, I was allways including js files from the view pages. But i can include it in the controller also using appendscript(). Which is the best method according to mvc ?
Javascript works with view output - the view knows, what javascript is needed to make everything work. And the view might not be directed to the browser, other view media might be used. For this reason, I prefere adding javascript from inside view.
Related
I've been looking for the answer I seek in many posts before. But none of them worked for me.
I'm learning CI currently and want to implement it with admin panel template called Clip-Two. I will give brief explaination about my problem.
Problem : In some of my pages the CSS works fine, however in some of the pages the partially loaded.
Below is my controller called Users.php
Users.php
Within this controller, i have two functions, mainly the first one is for index, and the second one is when i want to create a user.
In the first function, the CSS works fine. All the required CSS files are loaded shown below.
Index.php
However, in the second function, which have a new page, it only load partially of the whole CSS files.
Create.php
Below is my header template
header.php
The one that I highlight is the CSS file that doesnt loaded properly.
When I inspect the elements, the file path is wrong, shown below.
Elements
Below is my config file on base_url().
Base_url()
So, I'm confused, is it my base_url() went wrong or is it something else. Any help will be appreciated. Thanks in advance!.
Sorry I made a very long post, i just want everybody have a clear picture of my problem.
EDITED
I'm using admin template from Clip-Two
Below is the console error shown on my page.
Sorry I think my post is a bit misleading, I have edited my title and my problem
Problem : the jQuery from the template have the theme selector, so basically the jQuery could not find the path.
It shows that jQuery could not find the path.
Is this my problem lies on the jQuery?
Are you sure you are not manipulating with that stylesheet using JavaScript? (You have an id identifier on tag.)
Also, insted of <?php echo base_url()?>, try <?=base_url()?> it takes way less space.
I'm finally making the switch to OOP from procedural and starting with CodeIgniter and just looking for clarification. For every page that you would typically have (about.php) will you have both a view (about.php) and a controller (About.php) for every page? I'm trying to wrap my head around it and I've always given up and went back to procedural and now I'm forcing myself to learn object oriented.
That's certainly one way you could do it, but it doesn't have to be that way.
In CodeIgniter, your controller forms a section of your site, and looks in most URLs like a sub-folder, e.g.
http://example.net/products/tvs
There, products is the name of a controller, and tvs - in URL terms, the sub-page - is a method of that controller.
So yes, you could have a controller for each page, but no, you normally wouldn't. Think instead of controllers being responsible for site sections rather than individual pages.
The controller controls everything, you could have all your info in a DB, but if you want to have actual files, then put them in your "view" folder and just add a function in your controller.
Something like this:
controller:
function about_us_page() {// load your about_us.php view file here}
view:
about_us.php
and you should link to it like:
example.com/controller/about_us.php
I am using the codeigniter framework for my website.
Previously my website was working fine. But a few days ago I made some changes in code (I add some files for cron job).
When I made these changes my website is not responding it is continuously connecting to the server.
I am using the stencil with the codeigniter.
When I use the ordinary codeigniter view function:
$this->load->view('view_name');
It was working but as I am using stencil paint:
$this->stencil->paint('view_name'); // its not working.
Website URL: http://blogsetu.com/
I would recommend you to read the documentation again there is something you might have missed we can't say any thing without viewing the full source code
However I think you missed to set a layout
from http://scotch.io/docs/stencil
Bare Minimum to Get Started Set a Layout in your Controller
You always will need to set a layout. This is required for Stencil.
Layouts are located in "/views/layouts/". To learn more, visit the
docs about layouts.
$this->stencil->layout('default_layout'); Set and Load a View with
the "paint()" function
To set and load a view you will initiate the "paint()" function. This
function is the equivalent to "$this->load->view($view)" in
Codeigniter.
To learn how to bind data to the view, please click here.
These are located in the "Pages" folder inside of the views folder.
The HTML from these pages are made available in the layout as the
$content variable.
$this->stencil->paint('example_view');
I am creating a document in one the pages in our website and I have to disable the layout.
All the CSS and JavaScript files are included via Bootstrap and I echo those links in layout.
So now I still need to add those links in controller of the page.
My code in bootstrap as follows:
$view->headLink()
->appendStylesheet('/css/bootstrap-cerulean.css')
->appendStylesheet('/css/bootstrap-responsive.css')
->appendStylesheet('/css/charisma-app.css');
I am trying to use this appended links in the related controller without having to type them one by one. Is There a way for me to pull this from Bootstrap and echo in controller action.
Thank you.
its not a good idea to do any view operations in controller action.
maybe think about using different layout in that action?
I want to execute some code right before the layout is rendered, after all other code is executed. Where would I put that code?
I am specifically trying to modify the files referenced in the headLink, headScript, and inlineScript view helpers before they're used by the layout.
Here are the steps I want to take:
Loop over the files in those view helpers
Make a list of the local files
Remove local files from the view helpers
Reference the local file list as a parameter to a server script that combines them for a single HTTP request
Add that new combine script reference to the appropriate view helper
It doesn't appear that a Front Controller Plugin is going to help me accomplish this, and here's why:
postDispatch() gets executed after every controller action that's executed, and I need the full list of stylesheets/javascripts
dispatchLoopShutdown() gets executed after the controller action loop, but the layout has already been rendered at this point
As Rufinus suggested, I solved this by extending the View Helpers. My question from that angle as well as the solution is here.
see Orginal PDF created by Thorsten Ruf
(Mirror)
the very last part you can access via plugin should be dispatchLoopShutdown
EDIT:
For ZendFramework2 see http://zendframework2.de/en/cheat-sheet.html
or this gdoc