Even though PyroCMS is an excellent CMS to use and I highly recommend anybody and everybody using when the situation grants it.
However, my situation calls for a custom CMS that just has quite a bit of differences that I am instead developing mine with the use of some of the libraries I see out there that are free to use. The main one I am currently working with right now is Phil Sturgeon’s Template library.
Now since obviously he uses it for PyroCMS I am trying to match up as close to a file structure as he does with that so that the template system will flow smoothly without any issues.
I am currently in a quandary right now because I have my login form is not finding a partial and I’m not quite sure why. When my dashboard calls the metadata partial it loads it up just fine but something is amidst and is not loading it when I call it in the login form.
Here is my current login controller, login form view, and the file structure to ensure it is set up properly.
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends Backend_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->template
->set_layout(FALSE)
->build('login');
}
}
<head>
<!-- metadata needs to load before some stuff -->
<?php file_partial('metadata'); ?>
</head>
applications/
themes/
supr(my custom theme from template)/
views/
login.php
partials/
metadata.php
Any ideas from anyone?
In your controller:
$this->template
->set_layout(FALSE)
->set_partial('metadata', 'partials/metadata.php')
->build('login');
}
note the added call to set_partial.
In your view:
<?php echo $template['partials']['metadata']; ?>
Related
I am building a web server locally using CodeIgniter and am trying to add a new page to my website. However, after creating the Controller and View files for the page I cannot access the new page at (what I think is) the desired address.
This is on a Pi running PHP 5 and Apache 2 with CodeIgniter 2.2.6. I have been able to access other pages to work through just writing the Controller and view files, but I can not access this one.
Controller page code (file name: Display_Live_State.php)
<?php
class Display_Live_State extends CI_Controller {
public function __construct()
{
//Construct page
parent::__construct();
$this->load->helper('url_helper');
}
public static function view()
{
$this->load->view('Display_Live_State_view', $data);
}
}
?>
View page code (file name: Display_Live_State_view.php)
<body>
<div>This is a test</div>
</body>
I expect to find a page with the test sentence on it at path localhost/index.php/Display_Live_State/view as I have created other pages with similar filepaths (except for the name of the controller) and have been able to access them.
If someone could enlighten me as to where CodeIgniter 'puts' the website when created, or show me what I did wrong / where the page is if it exists, I would be very grateful. Thanks.
Change Display_Live_State to Display_live_state both in the class declaration e.g. class Display_live_state and in the filename application/controllers/Display_live_state.php.
Set your base_url if you haven't already to http://localhost.
You should be able to access your controller via the url: localhost/index.php/Display_Live_State/view
I'm using Codeigniter and facing the following problem.
In a controller, I want to include in some way an application (Not written in Codeigniter) in my controller. I am using file_get_contents now. It's working fine and the application is shown in the controller I made. The problem is, the application contains a lot of forms which are posted to other pages in the application itself. Using file_get_contents, the forms redirect the user to a target outside my controller. This may sound a bit vague, so here's an example:
The user navigates to the controller: 'game/login' and therefore wants
to visit the login page. The user fills in the form. The form posts
the data to assets/game/index.php?page=login. This makes the user
redirect to assets/game/index.php?page=login, and therefore making him
leave the controller page.
Does anyone have an idea on how to fix this problem?
defined('BASEPATH') OR exit('No direct script access allowed');
class Game extends CI_Controller{
public function __construct(){
parent::__construct();
}
public function index($page = ''){
file_get_contents(FCPATH . 'assets/game/index.php?page=' . $page);
}
}
You can load your external php pages in a iframe but i would suggest you should convert your php files to codeigniter MVC structure to get the advantages.
The quick way is using iframe,but i would ask you to refer this post to get an idea on Iframes when to use & when not to.
Are iframes considered 'bad practice'?
Im new to laravel, but im trying to integrate an existing php script that I have into the laravel app. I understand everything happens in a MVC based architecture. However,im trying to link this page into the header page whose path is application/view/templates/header.php.
For example, there is a controller present in application/controller/LoginController.php and that has a function called public function index() and the way which it is called from headertemplate is:
<li <?php if (View::checkForActiveControllerAndAction($filename, "login/register")) { echo ' class="active" '; } ?> >
Register
</li>
<li>
Administrator Login
</li>
As you can see when i try to call a script which is in the root directory, called admin.php it gives me a 404 - Page not found.
Im really struggling I hope someone can help me figure out the problem. A 404 error is never fun as it is only a tiny error.
If you really want to run a basic PHP script then you can always chuck it in the public directory or try routing it from somewhere else. You're using it as a login script for admins so I would highly suggest just reprogramming it to be a part of your laravel site. Totally up to you though, this may not be the best answer but it will work.
I would suggest do it step by step
Route
In your /app/Http/routes.php
Route::get('/login/register', 'LoginController#index');
Controller
Let make sure you create a LoginController.php in /app/Http/Controllers/
Function
In your /app/Http/Controllers/LoginController.php , create a function call index to return a view.
public function index(){
return view('templates.header); // <-------- /templates/header.blade.php
}
View
inside your /resources/views/templates create header.blade.php
Place all the HTML code needed in it
Test
go to http://localhost/login/register
should load what you place in side your header.blade.php
You shouldn't get 404 anymore.
I am a beginner to Wamp server. I am trying to design a website with project name as "helloall" in netbeans IDE.
In the views folder I have two files layout1.php and layout2.php.
I am trying to call layout2.php from layout1.php in the below style.
<div id="logo"> <span>LAYOUT2</span> </div>
But I am facing the below error, for which I am not able to find the reason.
The requested URL /helloall/layout2.php was not found on this server.
Do I need to change anything in the configuration? I am using all the default configurations.
as per Codeigniter standard you have to follow the MVC pattern so:
Model -> Controller ->view
now, assuming you want to visualize layout2.php view you have 2 chances:
1 - load view directly where you need $this->load->view('layout2');
2 - create url function ad hoc kind of www.site.com/layout/layout1 and www.site.com/layout/layout2:
controller layout.php
class Layout extends CI_Controller {
function layout1(){
$this->load->view('layout1');
}
function layout2(){
$this->load->view('layout2');
}
}
i really suggest you to look at How To Create a Controller in Codeigniter Doc
What I want to do is to create a mobile version of my web site in CodeIgniter.
I want to redirect my complete web site to m.example.com
There will be no change in controllers, neither in views and models. Both will be the same.
I don't want to change my .htaccess file. Any possible solutions for this?
The user agent class has a function;
$this->agent->is_mobile();
You could use this in the construct of your base controller(s) to test if mobile.
Instead of rewriting your code all over the place, you can just load a different view folder. In essence what will happen is you can just have CodeIgniter load a different view with the same name from another folder everytime you use $this->load->view("xxx"). First, create a new folder in your view folder called /mobile and just create views with the same exact naming conventions and it will load the the view accordingly by extending the Loader.php class.
Whether you are doing a responsive design or if you are going to create an iPhone app looking mobile version of your site, kind of like what facebook does, then you can just override the Loader class in the core folder. In your application/core folder create a MY_Loader.php and put it in that file.
Mine looks like the following
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Loader extends CI_Loader
{
//overides existing view function
function view($view, $vars = array(), $return = FALSE)
{
$CI =& get_instance();
$CI->load->library("user_agent");
if($CI->agent->is_mobile()){
$view = 'mobile/'.$view;
}
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
}
}
?>
Responsive web design is a mess in my opinion, but this still separates the code for you very nicely, while still being able to use your controllers and models in unison.
Hope this helps. This is the way I will be going about it :) !
Why a redirection? If everything is the same, why not look into Responsive webdesign?
24ways.org has some good articles for it:
http://24ways.org/2012/responsive-responsive-design/
http://24ways.org/2012/responsive-images-what-we-thought-we-needed/
Ok I found another solution. I used hooks pre controller and I redirect www subdomain to m subdomain.