how to integrate whole html template in codeigniter? - php

I also done a single webpage into the codeigniter.
But performing "href" it doesn't works.
Give a solution for how to include whole site into the codeigniter.
I think may be i need to create controller(into the directory) files for each and every view(into the directory) files.
Note : My whole templates are in the "view/pages" folder.
i already created "pages.php" in controller folder.
After changing route.php it only works on index.php. not for all other pages when perform links from index page.
My pages.php code is below
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Pages extends CI_Controller
{
function view()
{
$this->load->view('templates/header.php');
$this->load->view('pages/index');
//$this->load->view('pages/login');
$this->load->view('templates/footer.php');
}
}
?>

I dont understand you. Do you mean something like this?
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Pages extends CI_Controller
{
function index()
{
$this->load->view('templates/header.php');
$this->load->view('pages/index');
//$this->load->view('pages/login');
$this->load->view('templates/footer.php');
}
function aboutUs()
{
$this->load->view('templates/header.php');
$this->load->view('pages/aboutUs');
$this->load->view('templates/footer.php');
}
}
?>
In this way you reach your index page through www.yourserver.ext/pages/ (or www.yourserver.ext/pages/index) and, for example, your about us page through www.yourserver.ext/pages/aboutUs
Also you can set a param and load the page depending on it

Related

Stack with CodeIgniter, only index page load

Controllers/home.php code is:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function index()
{
$this->load->view('index');
}
}
?>
Config/routes.php code is:
$route['default_controller'] = 'home';
This code is for view only index page. I create folder in views named pitanja, and several pages in that folder. Problem is when i click on site on that pages, i get error 404 page. Where i miss?
$this->load->view('pitanja/index');// relative to APPPATH.'views' directory
Just store pitanja folder with application|system|user_guid and it will display pages. Solved!

How do I make codeigniter to load a HTML project?

I have a project which is this one:
Its just a html webpage with the features of letting the user modify the product the way they want, it currently does not have any backend.
I have done this:
In my app/controllers I have a made one controller named:desing
it has this
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class desing extends CI_Controller {
public function index()
{
$this->load->add_package_path(APPPATH.'third_party/desing_tool', FALSE);
$this->load->view('index');
}
}
I have the third party project in the folder third_party and my routing settings are this:
$route['desing'] = 'desing';
but it doesnt load, I want to add a shopping cart, I will make a cms but I cant make code igniter load this.
Any Ideas?

codeigniter - how to remove http://localhost/social/pages/envi --> pages where pages is php in social/application/controller

Here is my pages.php:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pages extends CI_Controller {
public function index()
{
$this->load->view('home');
}
public function event()
{
$this->load->view('event');
}
public function envi()
{
$this->load->view('envi');
}
public function tour()
{
$this->load->view('tour');
}
Can you guys help me out when click on button localhost/social/pages/envi this is opens.. but i need that file should be access and url should localhost/envi how to do that can u guys help me
There are number of ways for doing this
Like you can set apache rule in .htaccess file OR
Define your routing in this file
application/config/routes.php
Put this line of code in routes.php
$route ['envi'] = "social/pages";
URL will go like this
http://localhost/envi
Hi ShanmukSrinivas Gandepalli,
There a file routes.php in the config folder, open it add define your action here
Like below, here home is controller name and aboutus is method name. Now you can call this by aboutus no need to add contoller in the url.
$route['aboutus'] = 'page/aboutus';
Hope this will help you!

CodeIgniter - Hyperlink creation

I have tried to create a hyperlink to another page using anchors however it doesn't seem to work.
My function is called calendar and its stored in calcontrol.php within a controllers directory.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Calendar extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function index()
{
$this->load->view('calendar');
}
}
?>
I have tried other methods but they do not seem to work.
edit : this is my a href
Link
Filename and classname must be the same, otherwise CI will not be able to load it. And if using CI 3, make sure your class name and filename are both Ucfirst. If you have everything set up like this, then you should be able to view the page through http://yourdomain.com/calendar/calendar
Try this code. You forgot to load url helper. File Calendar.php - nogice capital C if CI3:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Calendar extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function index()
{
$this->load->view('calendar');
}
}

Codeigniter URI route

I have various static pages and I dont want to create independent controller for them all.
Say I want to create a controller named page and have all of the static pages as functions.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Page extends Frontend_Controller {
public function index()
{
}
public function store(){
$this->load->view('public/store');
}
public function contact(){
$this->load->view('public/contact');
}
public function about(){
$this->load->view('public/about');
}
}
Is there anyway to modify the URI routes so that I wouldnt have to type mydomain.com/page/contact but I could type mydomain.com/contact to view the page
In your application/config/routes.php
You can add as:
$route['contact'] = "page/contacts";
$route['store'] = "page/store";
...
In my application/config/routes.php I use the following regex to do that. Most sites I work on are relatively small so I list all of the controllers in the following snippet (because it's easier than listing all of the static pages)
$route['^(?!controller1|controller2).*'] = "page/$1";
The logic basically says that If the path does not start with controller1 or controller2 then use page as the controller for urls like http://domain.tld/page
For not having to create 10+ static routes for all my static pages it keeps it pretty simple.

Categories