Call A Controller Function In Another Controller In CodeIgniter?

I have a controller "user" in my codeigniter application. This controller has a function called logged_user_only():

public function logged_user_only()

Now I would like to call this logged_user_only() function in a function of another controller to check if the user is logged in or not? PS. If this can not be done, or is not recommended, where should i place this function to access in multiple controllers?


Call Function In CodeIgniter Controller?

I've got this code, but I'm not sure I make it work:


I'm not sure how to activate it is what I'm trying to say. I placed it in the controller and it's within a function for one of my pages. I don't have any syntax errors. I just don't know how to wake it up and make it work. I thought I could just put youtube_data_grabber('[URL]...but that didn't work. I got the code from this blog, and I have the zend functionality working. I tested it earlier and had no errors. I'm just having trouble with this youtube part.

View 2 Replies View Related

CodeIgniter - Turn Off Controller Function Call?

I simply want to load the controller and not call a function based on the URI, so that I can then generate the page based on the following segments. How do I change the default behaviour to do this? >>> thought all I needed to do was in config.php add:$route['find/(:any)/(:any)'] = "find/$1/$2";but this gives me a

class Find extends CI_Controller {
private $s1;
private $s2;


View 1 Replies View Related

Codeigniter: Call A Function In View From Controller

I am New to Codeigniter. In my Sample Application I add a new Tab called "RegForm" in my Main.php(View Folder). When i Click the RegForm Tab it load the New Window(width='800px' height='500px'). i understand the concept but i dont know how to write coding in Codeigniter. Basicall i call a function in Controller file when i Clicked the RegForm tab. and i need to call a function in View where i load a window with properties.

View 1 Replies View Related

Codeigniter Login To Controller - Protect Entire Admin Controller

I'm very new to Codeigniter, I'm trying to protect the entire admin controller. I figured I'd start here:

function Admin()

but this is obviously incomplete. How do I also stop the method that is trying to run ( ie index() ), and am I on the right track here?

View 2 Replies View Related

Codeigniter - Send All Requests That Do Not Match A Controller's Name To The Default Controller

I'm working on a project involving two kinds of URLs, one following the standard CI pattern[URl]..

And another presenting the following scheme:[URL].. I would like the second to call the default controller's handlecategory (or something like that) function with category as an argument.

Bonus love if you could also tell me how to let URLs like [URL].. call the same function passing just place as an argument if no category follows that URL, or both place and category if it does.

Additional datum: I already know the names of all controllers, places, categories.

View 1 Replies View Related

Call More Than One (or Multiple) Controller In Class Controller?

For projects written in php, can I call more than one (or multiple) controller in class controller? Example in [URL]....ASK: I need to call an action from another controller... And if I do like the picture above, I'm being out-ethics?

View 4 Replies View Related

Call Controller Method In View Or Another Controller?

I have main controller, that print main page.


How can I print last articles in header view?

View 2 Replies View Related

CodeIgniter Call Controller's Constructor When Calling One Of Its Methods Via AJAX?

I need to know whether I should re-call my helper redirectIfNotLoggedIn() inside ajaxFunction, since it's already in the constructor:


View 1 Replies View Related

CodeIgniter: Load Controller Within Controller?

I have a home controller with an index action that displays a set of featured products. However, the products are managed through a product controller including a proprietary model and views.How do I access product information from within the index action in the home controller? Instancing product won't work as the class isn't loaded at runtime and CodeIgniter doesn't provide a way to dynamically load controllers. Putting the product class into a library file doesn't really work, either.To be precise, I need the product views (filled with data processed by the product controller) inserted in the index view. I'm running CodeIgniter 2.0.2.

View 1 Replies View Related

Use A __construct Function In Other CodeIgniter Controller

I have a controller called member within this a construct function

function __construct()

I want to check in my other controller that user is logged in how i can use this function in my other controller called profile and others

This is my First project with CodeIgniter

View 3 Replies View Related

CodeIgniter 2 - Use Default Controller Function Without Specifying In URL

see the following controller in CodeIgniter 2

class user extends CI_Controller {
function __construct() {
function index($id) {
// do something here

So my URL would be [URL] But what I really want is to be able to not have the 'index' in the URL, so the URL would be [URL]

View 2 Replies View Related

Calling Javascript Function From Controller Codeigniter?

I am developing site using codeigniter.I have a form which contains add button and textbox. once the user enters the data i have to check whether it exist in database,if yes generate a dynamic textbox in the page else alert user. I have written javascript to generate dynamic textbox. My question is how to check in database??? how to call controller from javascript or to call javascript function from controller???

View 2 Replies View Related

Let The User Invoke A Controller Function In CodeIgniter

Here is a function in a Controller that lets a user log out. But how do I enable the user to do this? I would think the answer is to put a hyperlink in a View. But I can't figure out how to make a hyperlink that invokes the function. (And I'd rather not build a form ...) Source for this code

class Auth extends Controller {
function logout()
$this->data['title'] = "Logout";
//Library function
$logout = $this->ion_auth->logout();

View 2 Replies View Related

Refactor A Codeigniter Controller Function That Is Too Long?

I have a function in my controller that has grown longer than I'd prefer and I'd like to refactor it to call a few discrete functions to make it easier to manage. How can I better organize a long function in a Codeigniter controller?What I've tried:I know you can create private functions in a controller by naming them with a leading underscore (_myfunc), but then the variables in the function are out of scope for the calling controller function. So you have to return all the needed data from the function which is a hassle. Is this the best option for managing a complex controller function? Is there an easier way where the variables could all be global to the controller class like a standard class member variable?


View 7 Replies View Related

Call Function In Another Controller In Yii?

I've created 2 controllers in my Yii application: FirstController.php and SecondController.php in default controller path. FirstController.php:

class FirstController extends Controller {
public static function returnFunc() { return 'OK'; }


Calling FirstController::returnFunc() similarly don't work. I'm newbee in OOP and Yii framework. What's the problem?

View 2 Replies View Related

Write A Function In A CodeIgniter Controller Which Can Take Optional Parameters?

I'm trying to write a function in a CodeIgniter controller which can take optional parameters. However, I always get Missing Argument warnings. I'm not trying to suppress the warnings - I'm trying to declare the parameters as optional (maybe they could be empty strings if they don't exist, or something).

View 1 Replies View Related

Call A Javascript Function From Controller?

I have a form in my view page on submit a function in a controller called function Login() is called This is my Login function

function Login()
$EmailId = $this->input->post('mailId');
$Password = $this->input->post('password');


How to call a javascript from here

View 1 Replies View Related

Call A Function In Another Controller In Code Igniter?

I want to call a function in another controller. for example if user try to log in with incorrect parameter then the application will redirect to another controller and passing a variable (array).

class User extends Controller {
function User()

View 2 Replies View Related

Call A Function Based On Variable In Parent Controller?

I'm writing a micro MVC framework, and I want to be able to run a function based on the action in the URL given. I currently do:

function action($id, $function){

Where the $id is the model/view/controller to load, and the $function is the action. This apparently works, but not in the MainController. I'd have to put it in the startup script which would be limiting as I want people to be able to run action from inside the view so that they can perform different actions based on what they give the function.

Fatal error: Call to a member function testFunction() on a non-object in /home/cherwell/public_html/scott/develop/simple/system/controllers/MainController.php on line 20

I can call a function from the child controller from the MainController?

EDIT: I have made the action work by doing:

if($action != false){
} else {

$id and $action are always defined, so it works fine. The only problem I have now is that any functions must have all of the globals (its a long list):

global $id;
global ${$id};
global $site;
global $start;


if they need any of these (which, they do if you need to call methods from the maincontroller/helper/model)... I don't know why variables aren't being passed down into the functions. I have declared the class for the respective ID too...

EDIT 2: Example.

function testFunction(){
global $helper;

Works, but when I remove the global $helper; it fails. Even if I have a load of globals in the startup, construct of child and parent, it still fails. This also happens for every function (needing globals).

View 4 Replies View Related

Call A Controller Within A Controller?

As far as best practices go is this recommended? I have a comments controller + model that needs to be called in an items and profiles controller. The comments controller automatically loads the comments model.Is it acceptable to call the comments controller directly from the items and profile controller, or is the "best practice" way to call the comments model instead?I ask because in kohana, the view isn't a singleton class so if I were to call a controller within another controller I end up with two views. On the other hand, if I were to just call the model, there would be duplicate code within the items and profiles controller.

View 3 Replies View Related

Pass A Post Value From View To Controller To Model And Back To Controller In Code Igniter

I'm creating a login form with Codeigniter, and I have a controller that collects the inputs from the form, then I want to check to make sure what the user entered is in the database, so I'm collecting those values in the post and want to send them to the model for the database connection.

Then if the results are in the database I want to send something back to the controller with a yes or no and then I can go from there. I'm kind of stuck, but this is what I have so far: The controller:


View 3 Replies View Related

Magento: Why Do Controller Action Predispatch Events Not Fire If The Controller Is Rewritten

Why do controller action predispatch events not fire if the controller is rewritten? Here is a snippet of store/app/code/core/Mage/Core/Controller/Varien/Action.php:

abstract class Mage_Core_Controller_Varien_Action
// [...]
public function preDispatch()
// [...]
if ($this->_rewrite()) {
return; // [What is the purpose if this?]

I don't know where to start fixing this problem. Anyone out there ever dealt with this before?

View 2 Replies View Related

Kohana 3: Prevent A Controller Action Which Renders A Subvew From Rendering If Not Called From Approved Controller

Let's say I have the domain [URL] It has a default controller called 'account'. This controller is based on a template, and creates a view using it's data, and the result of a couple of other controller's renderings.

Let's call the other controllers, 'game', and 'stats'. These 'sub-controllers' call View::factory with their own model data, and then the whole thing is rendered for the user. I don't want people to be able to enter in to the browser [URL] or [URL] and see the sub-controller's views rendered without the template of the main 'account' controller template.

View 2 Replies View Related

Create A Zend Framework Controller / Action Url Outside Of Controller?

I use the zend framework 1.11.2. I want to create URLs to controller actions that can be used inside email texts.

Within controllers I have done that with Zend_View_Helper_ServerUrl and Zend_View_Helper_Url like this:

$serverUrlHelper = new Zend_View_Helper_ServerUrl();
$unsubscribeUrl = $serverUrlHelper->serverUrl(


Now I want to do this not within a controller but instead from command line. I already managed to start a zend controller/action by following the steps described here Running a Zend Framework action from command line. But the Application_Router_Cli does not have an implementation for the assemble function. I never have done something deeply with zend routing.

View 2 Replies View Related

Passing Data From One Controller To A View In Another Controller?

In zend I'm interested in passing data from one controller to a view in another controller. For example, I have a search controller whose purpose is to use the search model to query SOLR, and I want to have Index Controller call it from the view (via ajax or other means) and have Search controller return data to that view.

View 1 Replies View Related

Way To Bypass Controller In CodeIgniter?

I've been using the CodeIgniter framework for PHP and am enjoying it, but I notice that it seems to require a controller for every view. I'm wondering if there is a way to call a specific model from the view itself, rather than route through a controller. I understand that use of a controller is best practice in most cases, especially where the data from the model needs to be modified in some way, but I have cases where I just need to do a strict data pull to the view (which is loaded via ajax), and setting up a controller for that seems superfluous.

View 6 Replies View Related

Hide Controller Name In The Url In CodeIgniter?

so the thing is I'm using .htaccess to hide the index.php but I still get the controller name in the url like that: [URL]

View 2 Replies View Related

Removing Controller Name From URL In CodeIgniter

Currently in my CI project I have a single controller that handles all things account. Such-as register, login, activation, etc. My routes work as such... [URL] How can I remove account from the route while also being about to remove the controller from other pages. I basically want the controller to always be removed. One of my reasons for this is SEO, search engine rank the importunateness of a page based on how deep it is in a website. The only way I have seem to achieve this is to do some thing like route['activate'] = 'account/activate'; for every single page, which would be a huge hassle.

View 4 Replies View Related

Codeigniter Cannot Extend Controller

I have created an admin controller that extends the blog controller (both are located in application/controller). However, when I tried to access the controller, it gives me an error that the blog controller was not found.

If I put require_once(APPPATH.'controllers/blog.php'); inside the admin.php file it works. But I'm just wondering if there's another possible way to extends the blog controller without having to use require_once inside the admin.php

View 2 Replies View Related

Codeigniter Not Finding The Controller?

This is my basic file structure

- /application
- /config
- - -routes.php
- /controllers


And in routes:

$route['admin'] = 'admin/dashboard'; //This should be the default.
$route['admin/(:any)'] = 'admin/$1';

Browsing to results in this error;

An Error Was Encountered

Unable to load the requested file: dashboard.php

I've read the documentation on controllers and sub-folders are supported.

View 2 Replies View Related

Copyrights 2005-15, All rights reserved