How to create 'blog' and new page in Fuel CMS with CI - php

I am just starting out with fuel CMS and Codeignitor. I'm looking for easy to read suggestions, references, tutorials, code snippets, ANSWERS etc for the 2 following questions below. (2-part Question)
1.) How do I access 'blog' functionality; I've read it is built in as a /view/blog.php but I don't see it; I've tried to create my own (in same directory) but it simply resolves as a static page (I created it from the dashboard) but it lacks any blog > post > get post functionality; like 'blogs' do. I've read time over, like Wordpress and Drupal; Fuel has a 'blog' template. There is none under 'layouts' as well.
So, at this point, I wouldn't mind creating my own 'blog' page - Which leads to:
2.) How do I create a new page manually in Fuel CMS, without the dashboard.
I've created an empty .php file in this directory per documentation:
C:\xampp\htdocs\FUEL-CMS-master\fuel\application\views
I don't really need a custom _variables/ with this -- so what am I missing. I've read I don't need to add / set a new controller with this type of page nor static pages. I also don't want to have to do anything with the controller if I don't need to.

Codeigniter works on CMV Controller - Model - View so to create a simple page you need to create at least 2 files 1 controller and 1 view
if you are using CI 2.2 http://www.codeigniter.com/userguide2/overview/at_a_glance.html
if you are using CI 3 http://www.codeigniter.com/user_guide/overview/at_a_glance.html
first you need to create controller
second create your view
create a file in application/controllhers/blog.php
<?php
class Blog extends CI_Controller {
public function view($page = 'home')
{
//you can acesse this http://example.com/blog/view/
}
public function new($page = 'home')
{
//you can acesse this http://example.com/blog/new/
}
}

Related

silverstripe: use another "root" - template instead of "Page.ss"

Is it possible to render another "root" template instead of the Page.ss file for some specific pages / controllers? There are already some pages using the Page.ss template, but now there will be a new "Intranet" section on the website where the pages should have another "root" template: IntranetPage.ss.
Page.ss should stay as is and should not be touched at all.
I mainly want different "root" templates because both templates load different JS and CSS files. Also the "container" HTML is quite different.
I was able to create a custom controller which does manually what I need. Something like this:
class IntranetPageController extends PageController
{
public function index()
{
return $this->customise([
'Layout' => $this->renderWith(['Intranet/Layout/IntranetPageLayout'])
])->renderWith(['Intranet/IntranetPage']);
}
}
The code is inspired from here: https://docs.silverstripe.org/en/4/developer_guides/templates/rendering_templates/
IntranetPage.ss is used now as the "root" template. IntranetPageLayout.ss is displayed for the $Layout placeholder.
That seems to work, however I have many pages which have to be based on IntranetPage.ss. It feels strange to write for every new Controller the very same index function (with a small adjustment to load another LayoutPage).
I am sure, Silverstripe has some convention to do that automatically :)
What I need is very close to having a individual theme per page, but I am not sure if that is possible...
Instead of extending PageController, extend your IntranetPageController in new controllers. Whenever index is called, it will call your index function from your parent class, in your case IntranetPageController.

Joomla 3 - Custom Component - How to access site model from Admin View?

I used component creator to generate a custom component for Joomla 3. I have a view in the Administrator panel that would require a function from a model in the front end.
I have been doing google searches for several days trying to locate an appropriate answer, this is the closest I have come to a working response:
How can I include multiple models in one view for in a Joomla 3.x component built with Component Creator
However, in that response he seems to be using a site view model from another site view.
Here is a little bit about my component structure:
name: com_stargazer
Admin View: email
index.php?option=com_stargazer&view=email&layout=test
/administrator/components/com_stargazer/views/email/tmpl/test.php
Site View and model: returnpage
/components/com_stargazer/models/returnpage.php
/components/com_stargazer/views/returnpage/tmpl/default.php
I tried to modify my admin view to include the site model by including the path:
$this->setModel(getModel(JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_stargazer/models', 'returnpageModel')));
$this->setModel(JModelLegacy::getInstance('returnpage', 'stargazerModel'));
// assigns array from the second model to 'ItemsOtherModel.' there is no '$' sign used.
$this->ItemsOtherModel = $this->get('tags','returnpage');
However, getModel doesn't seem like it's accessible from the view. (Probably the controller only?)
Other, references say to modify the controller (Additional references posted in comments):
https://docs.joomla.org/Using_multiple_models_in_an_MVC_component
Over the last few days, I have tried various iterations of the above referenced code samples . . . Ultimately I am confused about which controller to modify? Do I need to modify the admin controller to get this to work, or the site controller? Would it be easier to add the function to the admin model, and access it on the site view?
It's also been difficult to debug since I don't know which model is throwing the error. My best guess so far though is that I've had NO luck attaching at all to the site model from the admin view. Any help would be appreciated in getting this sorted out.
This is my first question, so I hope that it is clear enough.
I can clarify if needed.
Thanks in advance.
To call a frontend or backend Model you can use JLoader or even require_once to include the model file.
Using JLoader you can call the model inside admin view like this
JLoader::import('joomla.application.component.model'); //Load the Joomla Application Framework
JLoader::import( 'returnpage', JPATH_SITE . '/components/com_stargazer/models' ); //Call the frontend model directory
$tags_model = JModelLegacy::getInstance( 'returnpage', 'StargazerModel' );//Instantiate the model
$tags = $tags_model->gettags();
And you can also use require_once
require_once JPATH_COMPONENT_SITE.'/models/returnpage.php';
$tags_model = JModelLegacy::getInstance( 'returnpage', 'StargazerModel' );//Instantiate the model
$tags = $tags_model->gettags();

CodeIgniter building a CMS with different page types

I've just started to get into MVC with PHP and have had a good mess about with the likes of CodeIgniter and CakePHP. I'm interested to find out what people's approaches to the following would be:
Normally when I have built a website with a CMS in the past I have approached it by having a core URI table in my database. Each URI is unique and represents a page on my website (e.g. www.example.com/about would reference a record in my URI table with 'about' as the unique URI). The URI table also contains a 'type' column which tells the system what type of page it is (e.g. splash, basic, gallery or whatever). Each 'type' has a corresponding table in my database with all the data for records of that type in them (e.g. I would have tables: basic, gallery and splash). The type also tells the system which template/pagehandler to load which in turn does what it needs to do for each page type.
So if you go to www.example.com/about, my system looks in my URI table for a record with URI 'about', finds it's type to be 'basic' so it loads the basic template/pagehandler which uses the basic table in my database to load and render the page. In the CMS I follow a similar approach, I'll have add/edit forms for all of the different types in my page manager.
I was wondering how you would approach this using an MVC framework such as CodeIgniter? I essentially want to have different controllers for each type of page on both the front and back. However, when someone get's to my site, they will end up on a URI with a single level so I need to check the type of the page and pass off to the correct controller. Is there a way you would recommend of checking the type of each page and then loading the relevant controller to do the rest of the work?
My approach eventually was to extend the _parse_routes() method of the Router class to check the database for any records matching the current uri and set the request with the corresponding value from the database.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Router extends CI_Router {
function __construct() {
parent::__construct();
}
function _parse_routes() {
require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$routes_table_exists = $db->query("SHOW TABLES LIKE 'routes';");
if ($routes_table_exists->num_rows > 0) {
$uri_routes = $db->get_where('routes', array('uri' => $this->uri->uri_string()));
if ($uri_routes->num_rows > 0) {
$row = $uri_routes->result()[0];
if (isset($row->request)) {
return $this->_set_request(explode('/', $row->request));
}
}
}
parent::_parse_routes();
}
}
Whether or not it's the best approach to take it seems to work so far.
Usually its a combination of Routes and naming your controllers. so for example you have an About page, and you don't need a separate About controller. Lets say you have a general Pages controller, and then a view($page) method to retrieve and show the page.
example.com/about
$route['about'] = "pages/view/about";
if you just have a few pages there are advantages to hard coding the routes - it protects your database. but otherwise taking an example from the tutorial
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
this does the same thing but now it will take example.com/anything can go here
Versus something like a contact page - where you probably want to have a separate controller called Contact, because you will need to validate the contact form, add it to a database, email it, show a response, show the form again if did not validate, etc So then you can just do a simple link to show the contact form: example.com/contact
the contact form submits to: example.com/contact/submit
more about Routes
http://ellislab.com/codeigniter/user-guide/general/routing.html
and definitely look at the tutorial it will give you more examples about routes
http://ellislab.com/codeigniter/user-guide/tutorial/index.html

Zend same template for different modules

I am developing a system which has multiple user levels. However most of the time the views inside each modules should be the same.
For example a user view should be 99% identical to the admin view however an admin can have some small extras like delete buttons on user posts etc.
What is the best approach to not duplicate a ton of template view files within each module?
The best solution I can think of is using the _base module and putting the view files in there and inside them do an (if($user->isAdmin(): extra HTML bits) and have both the user module and admin module render the base module views?
If you are creating template file(layout.phtml) in your /module/Application/View/layout/ folder, then the layout will be applied for all the views.
If you want to disable layout for some specific view, you can use like this:
public function yourAction() {
$viewModel = new ViewModel(array(
'foo' => 'bar'
));
$viewModel->setTerminal(true);
return $viewModel;
}
Very first need to check if user is admin then in view you can call another view partially having extra code like delete button using $this->partial() helper.

How to start a new website project in codeigniter?

I'm really beginner to codeigniter I'm working on CI since last 2 weeks. During this period I have created many views.php files, some controllers.php files and some models.php files
Now I want start a new website project.
What should I do. Should I delete all files of my controllers, views and models, etc., and download another codeigniter and start from the beginning?
You should check the documentation of codeigniter for help but just to give you a quick start ill explain how to create your first codeigniter project.
Installation
1 Download the codeigniter framework from http://ellislab.com/codeigniter
2 upload it in root directory of your website or local apache server directory.
Creating your codeigniter project.
In codeigniter your controller will handle the url requests and load appropriate model and views. So the first step is to create your controller.
1 Creating your controller: go to Applications->controllers and there you will find a built in controller called welcome.php.
This controller loads a view welcome_message.php which is inside Application->views.
You can use this controller or create your own.
To create your own controller create a new php file myfirstcontroller.php and extend a class with same name from CI_Controller.
Note that the name of the file and your class name should be the same. the index function is the default function that will be called when you make a request to the controller
class myfirstcontroller extends CI_Controller {
public function index(){
$this->load->view("myfirstview");
}
}
so when you request this controller through yoursite/index.php/myfirstcontroller
it will load a view called myfirstview.php which will reside inside applications->views.
Go ahead and create this file in applications ->views.
2 To pass data from controller to view you will send an array to the view
class myfirstcontroller extends CI_Controller {
public function index(){
$data['name']="My first application.";
$this->load->view("myfirstview",$data);
}
}
3 You can access this variable in view
echo $name
and it will output your variable
3 you use models you have to create a file inside applications->models and call it from controller and it will return the result in the form of array.
You can look at the documentation for further help.
Hope this helped you to get started with codeigniter.
The user guide is inside your download library.
You can also view it in http://ellislab.com/codeigniter/user-guide/
Good luck!!!
Here is Phil Sturgeon's article on how to do multiple site on one CI instance, in here he explains 2 ways of doing it and describes pros and cons.
http://philsturgeon.co.uk/blog/2009/07/Create-an-Admin-panel-with-CodeIgniter
But in his latest articles he has told what happened to modular separation.
http://philsturgeon.co.uk/blog/2010/03/modular-separation-codeigniter-2

Categories