I'm programming my first site in symfony2, a site including some bundles for handling articles and static pages or contact page. I'e also created a bundle (backend only for now) for handling ads to show in the site, but this ads must to be shown in ever frontend page request, so I need to understand how to execute the necessary code to retreive the ads to show and pass this information at all the frontend controllers I have in mine bundles.
Can you help me?
Thanks in advance
Robert
Depends where do you keep your ads, but sounds like a job for service container.
Basically you need to write a service that implements method to fetch the required ads and then call that service in the controllers ($this->get('service_name'))
See Embedding controllers within a twig template.
http://symfony.com/doc/current/book/templating.html#embedding-controllers
Basically if you want to include a global widget, you'll have to add it to the parent twig template in which your controller's template inherits.
Related
I readed doku and search about middleware on october informations, but nothing find what me can help.
My Problem:
I created Plugin and use RainLab User Plugin for Frontend Editoring of Content.
Frontend Content spilt up on Section, Group and Article.
Single Users become different access: hiddem, show, edit and more for sections and articles.
The site works with one plugin on content load dynamic.
How i can load content for single user by access config?
My solution:
I added on backend some functions to give access for users.
rainlab user content access
All access configs saved and works.
My idee is to create middleware to load content but i find nothing what can help me.
Docu tell me you can create middleware but middleware load all time on frontend, backend, all pages on website. This is not good solution.
https://octobercms.com/docs/backend/controllers-ajax#controller-middleware
In addition comes if i debug on middleware, so rainlab user functions not working, no informations about url request.
Why add middleware when you must load and create all classes and functions by himself??
I need middleware only for frontend and only for plugin or component.
I hope somebody can me help to find another solution or idee to fix it.
I think there is nothing left but to implement the content access in respective component on onRun function. :( and problem by this solution is: return Redirect not working outside a class or function (only on onRun)
There is Problem with your approach, as you want middleware and also you want to make sure it run for specific plugins and component. middleware worked based on request and request may have information about URL etc. but not about plugin & component etc so it can not determine when to run based on plugin etc..`
So you may use Different approach. and it will work with Frontend also with ajax requests.
You can create component inside your plugin, It will assessment all the access for logged in user if user is logged in. if user is not logged in you can provide different assessment access.
Now you need to add this component to your layout and now all pages which are using this layout have this access information from the beginning.
Now this component inject access information to page, So your Page and plugin's components can have this information readily available. now from your component inside onRun you can handle redirect at very top.
Component is not to define access, its just inject predefined access information which is in database [ as you said you use users plugin so fetch it and inject it ] to the page
Component will be specifically just inject access information to page. And that Component will be on layout so. it will automatically trigger for that layout pages. so it will executed first and based on that you can decide how to use it. you can also render conditional component based on that. as you can have access information in markup part as well so
if you have any doubt or questions please comment.
I am new to Joomla component developement and currently fighting with certain basic design patterns!
Lets say, I am developing a component where users can enter simple notes into their personal notebooks.
On calling the view "index.php?option=com_notebook&view=notes" I simply show a list of all note entries of the user. No problem so far, this is working fine.
Now I want to extend my component with the following feature: on opening the view "index.php?option=com_notebook&view=notes", I want to check if the user has already created a notebook before. If yes, I show all note entries, if not, I want to load a different view which contains a form to create a new notebook with certain options.
But how can this be done in a clean way?
For sure, I just can implement the form within the view "notes", but this is not the clean way, isnt it?
I also tried to override the function "display()" of the main controller and set the view manually if no notebook exists. But if I do so, I have to handle all calls to other views of my component manually within the function "display()". To solve this, I created a copy the original implementation from the class "JControllerLegacy" and changed it to my needs - this is working - but is this really the best way to handle problems like this?
So I ask you, what is the best approach to solve this problem?
Thx a lot!
According to me the best solution of your problem is to provide "New" and "Edit" button to your notebook listing page and create edit view of notbook. Same as Joomla has articles and article views.
So, As you mentioned above if use dose not have any notebook then he/she can create a new notebook using that "New" button. when user clicked on "New" button he has blank form where he/she can create new notebook.
here is the example how to create listing and edit view in Joomla. Hope this will help you.
https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_backend_actions
I am working on my SaaS app which is going to require a Custom ViewModel to be built to populate widgets (left,center,right,footer, etc)
I started off using a BaseController
`class BaseController extends AbstractActionController {`
But since I am going to try to use modules like ZfcUser etc I was wondering can I create a module that builds the ViewModel and if so where/how should I hook into the event to not break forwards/redirects?
My thought is build the larger view model without interfering with normal controller behaviors. The controllers would just pass back their normal array() for the viewmodel and it would be placed it
`<?php echo $this->content; ?>`
Ok clarification on a website you generally have Header, Footer, Content and say Left Nav. So the footer has 3 columns Login Box, Lastest News, and twitter feed, the left nav has Navigation and some ad's
All this really doesnt pertain to the Controller and Action being called so I am trying to find the best place to fetch the ViewModel and how then build and populate with all these external entities (login template,twitter, Nivo Slider) and replace.
Then when the controller returns its array() have it replace the $this->content in the layout
Putting all this in each Action would be huge and would break outside module use.
I suggest to using zf2plugin, but it works with zend forward helper and maybe you don't want this.But there is a closure result mode that you can generate some dynamic content ..
Try it, hope be useful.
you maybe want to create viewhelpers located in modules like a TwitterFeed-Module. the view helper would access a service from the same module.
The TwitterFeed Service would simply request the feed from twitter (and ideally cache it for an hour or so). the viewhelper would just render the data as needed or use a viewscript for rendering or return the raw data to be processed in the layout itsself.
Could someone tell what is good logic for creating custom helper for Views?
What I would like to accomplish is...
load header
load main navigation (static for all pages)
load some widgets etc. (static for all pages)
load content/main pages (dynamic)
and in the end, load footer of course
Could someone point me to the solution?
Thanks a lot, in advance!
This question gives some explanation to the method dqhendricks describes. It includes code examples showing how to use $this->load->view() to return the view to a variable instead of outputting it to the browser, how to include sub-views, and using a specific view as your main template. It's the best way I've found of handling view logic. Getting the hang of CodeIgniter - Templating / loading views
Some people will create a master template, then pass the sub content's view name in the data object. The master template will call the header view, footer view, etc, and use the data array to dynamically display the correct sub content view.
For a Template library that is more actively developed than Collin's (linked by predrag.music) try out mine:
https://github.com/philsturgeon/codeigniter-template
His is good but this supports modules, themes, mobile version variations of themes and plenty more.
you could use inheritance chaining (with a custom controller class or with an included extra class that extends controller that you extend from your controllers instead of the controller class) to make a common controller hub for all pages that has a method for the top stuff, and a method for the bottom stuff.
If you need something for the reference this one is good:
http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html
I developed an application with different MVCs using the Yii Framework
For example
I created a crud layer for Student Contact details and Student Courses etc.
All worked perfectly since each had its own menu, and when clicked eachs own view rendered.
Now my client wants everything on one page, and is quite persistent, we are talking about 7 MVC that need to be displayed on one page. Each MVC has it's own controller, model and view and own DB table. How can I render all of them on one page without re-writing the whole application? Is this possible.
If I understood your problem correctly, you simply want to merge all menu items and show the full navigation on each page.
By separating menus into standalone views and including each and one of them into a navigation view, you can have a well-structured non-repeating code.
$this->renderPartial('anotherView');
is pretty much everything you might need to know to get started. This is only callable in views as $this refers to the current controller object.
You can use views from other controllers:
$this->renderPartial('application.views.student_Contact.show',array('model'=>$model));
Hope this helps.