Mini CMS - need some advices on pages - php

I am going to write a super small cms with https://github.com/panique/mini/
Now I want to add a small pages section in the Admin of the site (this can be done easily ).
The advice part comes here:
The url of the mini framework is mostly easy, its /controller/method ( if its the index method then it won't needed to be shown in the url ).
So there is a file which checks if the controller is existing so it can load it.
But the thing is an user is not going to create a controller every time after creating a page.
What would be the best approach to do this ?
This file is checking if that controller exist: https://github.com/panique/mini/blob/master/application/core/application.php
Thanks in advance

The way this handles routing, is much like CodeIgniter. The path would be controller/method/arg1/arg2/arg3..., so you can write a controller, define a method which accepts one (or more) arguments to load user pages.
Assume, user has created a page named news. He/She may load the page via URL pages/view/news.

Related

Laravel 5 route returns view but changes url

Im not even sure if this is possible but what I am trying to do is this. I store different page modules in a database. When someone goes to a page with one of these modules, the pageController recognizes its a module and ( using the redirect path stored with this module in the DB ) redirects them to a get route which is how I know what info to pull and put on the page.
For instance, if someone was to go to /photo-album the pageController would recognize that was a page module and returns the redirect ( redirect/photo/albums ) and then redirects them to that route.
Route::get('redirect/photo/albums', ['uses' =>'PageController#getPhotoAlbums']);
The problem is the url then becomes /redirect/photo/albums. I would like it to maintain /photo-album
The reason I am doing it this way is because there will be several modules stored and each one will contain different things ( think blog, photo albums, video gallery etc. ). I need the redirect to figure out what goes on that page and what view to show. In this case PageController#getPhotoAlbums goes to the getPhotoAlbums method, pulls the photos and serves up the photoalbums view.
There may be a better way to do this and i'm open to it. Thanks in advance.
I don't have enough rep to comment, so I'll put this as an answer and hope it helps:
You really shouldn't get data from another controller. All your data should be available in the Eloquent model. This is important to the 'MVC' architecture.
There is more discussion on this here: Laravel: Load method in another controller without changing the url
So essentially, when your controller recognises it as a page module it should pull that data from the DB using Eloquent and then pass that to a View. That will mean that the original request URL is still retained.

PHP MVC - Where/when to load shared page content ('modules'/'widgets')?

I'm trying to build a simple PHP MVC framework. What I have right now is a basic set-up with a router that sends the request to the right controller, so I'm making the URL
/blog/[id]
Resolve to a class method like
Blog->singlePost();
Within singlePost(); I then interact with the model to get the right blog post and send it off to the view. The basic MVC triad is all there.
But pages are more complex than this. I've got a sidebar that I need to fill with data (from the database and other sources). I've got a main menu to build, I need to show the details for the current logged in user, and more. But, that said, I don't need all of these sections on every page.
My question is, where do I initiate/build all these various shared sections for the view?
My options that I can think of are:
Have every controller send a request for the required additional sections to be built (would have to update every controller each time something is added, no way)
When mapping the URL's, define a group that the route belongs to that loads in all the required sections (Not ideal, not every section will be needed on every page, could get messy)
Have the View (or Template) embed these sections on-demand. So the data for these sections would not be retrieved until the view explicitly asks for the data (The basic functionality of this seems quite appealing, but does it break the rules of what the view should do?)
Something else?
3 Seems quite appealing to me because I'd like for my templates (that will be dynamic and switchable via a template system) to be able to request a section on any page. So one template may show the "Top 10 Blog Posts" on the homepage, but another may not, so there's no point in loading it. I see that with Symfony/Twig, you can do this: http://symfony.com/doc/2.0/book/templating.html#embedding-controllers
Is this a good idea for various modules on a site? Or should everything be loaded before the view starts being processed?

Creating Dynamic Controllers in codeIgniter via CMS

I'm currently building a CMS for a project in codeIgniter and I was wondering if there's any way to create dynamically a controller file in codeIgniter via the CMS when the user create a new page in the database. I don't need to create another model because the tables in the database will be the same, as well as the view. Basicly, all the page in the website (link, title, content etc.) are from the same table. I just want to keep the uri like this (www.mywebsite.com/class/function). Also no routing.
I was looking around the web and the only thing I found close of my request is the CRUD "codegen", but i can't use it online and there's alot of things I just don't need from it.
While it is possible to create a new controller each time the user adds a new page to the database, would it not be better to have a single controller which takes the db id or page name as parameter and loads that page?
So if the user created two pages called page1 and page2, and you have a controller that is used to serve all dynamic pages named dynamic.php then the urls would be
www.mysite.com/dynamic/page1
www.mysite.com/dynamic/page2
Creating a controller each time the user creates a page is a big overhead, and also would require lots of code to properly implement, like deleting the controller when the user deletes the page from database, for instance. And I think to provide a coding solution within SO would be cumbersome.

Custom tags for my very small cms (Codeigniter)

I'm developing a very small cms kind of thing. So far I have a page controller that lets you add pages. And there is a frontend controller. All calls are received by the frontend controller and respective page is displayed. Now I want to allow some custom tags while creating a page. I am using CKEditor and I want that while creating a page user gives a tag like <!--cmsform_printform--> and this tag will print printform method of cmsform controller.
For this I have created a controller cmsform that has a method printform. In my fronend controller I have created a method replace_tags that searches tags and then call respective controller and method.
But now I realized that my logic was false because I should not load a controller in another controller. I can't think of anyother logic. Please someone guide me or redirect me to a good codeigniter tutorial that explains this.
Thanks
Have you tried writing a helper instead? The functionality you describe sounds more like a helper method than a controller action.
CI manual in their site lists several excellent video tutorials, notably the ones published on NetTuts+. You might want to have a look, if you haven't already. Also, please do search CI forums. They contain plenty of information on pretty much any CI-related topic.

Combining multiple controllers on one page, without loading controllers from a controller

I'm trying to create a page that displays certain widgets/includes dependent on the users permissions. I'm quite new to CodeIgniter and MVC.
Example.
I have a calendar. This has a controller, model and view and it needs to be included on other pages.
I want this calendar and a number of other similar 'widgets' to be displayed on one page. This page currently has a controller and view.
I know I shouldn't be loading a controller from another controller, but can't see a way round it.
Can you load multiple controllers from a helper, or do I need some form of template?
Thanks,
Jacqui
It sounds to me like you are looking for Modular Extensions for CodeIgniter. This allows you to break an application into modules that can be called from one another. In your case, you would have a calendar module which you could call from your other modules.
What you might be looking for is something called Layouts. Codeigniter does not have such a feature out of the box but layouts are basically delegating a (front-controller) request across multiple actions. Each action works on it's own and has it's own view assigned.
The layout will take care to put this all together into one output then.
This methodology takes care as well that you don't call one controller from another controller so you keep code apart that does not belong to each other or would get messed up because it does too much at once.
This discussion might be interesting for you: Codeigniter layouts?, the Codeigniter FAQ has more about it as well and more specifically Header and footer and menu on every page in the wiki.

Categories