Call A Controller Function In Another Controller In CodeIgniter?

Jul 11, 2011

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

public function logged_user_only()
{
[code]....

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?

ADVERTISEMENT

Call Function In CodeIgniter Controller?

May 28, 2010

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

[code]....

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?

Feb 10, 2011

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?g.example.com/class/function/ID >>> example.com/class/ID/IDI thought all I needed to do was in config.php add:$route['find/(:any)/(:any)'] = "find/$1/$2";but this gives me a 404.example.com/find/item/location

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

[code]...

View 1 Replies View Related

Codeigniter: Call A Function In View From Controller

May 26, 2011

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

Nov 24, 2010

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

function Admin()
{
parent::Controller();
if(!isset($_SESSION['loggedin'])){
$this->login();
}
}

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

Dec 22, 2010

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?

Jan 10, 2011

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?

Oct 15, 2010

I have main controller, that print main page.

[code]...

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?

Jul 17, 2010

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

[Code...]

View 1 Replies View Related

CodeIgniter: Load Controller Within Controller?

May 22, 2011

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

Jul 13, 2010

I have a controller called member within this a construct function

function __construct()
{
parent::Controller();
$this->is_logged_in();
}

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

Feb 6, 2011

see the following controller in CodeIgniter 2

<?php
class user extends CI_Controller {
function __construct() {
parent::__construct();
}
function index($id) {
// do something here
[Code]....

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?

May 3, 2011

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

Aug 8, 2010

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();
[Code]....

View 2 Replies View Related

Refactor A Codeigniter Controller Function That Is Too Long?

Feb 10, 2009

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?

[code]...........

View 7 Replies View Related

Call Function In Another Controller In Yii?

Oct 26, 2010

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

<?php
class FirstController extends Controller {
public static function returnFunc() { return 'OK'; }
}
SecondController.php:
<?php

[Code]...

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?

Jan 6, 2010

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?

Jul 1, 2010

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');
$res=$this->friendsmodel->CheckLogin($EmailId,$Password);

[Code]....

How to call a javascript from here

View 1 Replies View Related

Call A Function In Another Controller In Code Igniter?

Nov 24, 2010

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()
[code]....

View 2 Replies View Related

Call A Function Based On Variable In Parent Controller?

Nov 3, 2010

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){
${$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){
${$id}->{$action}();
} else {
include("system/views/".$id.".php");
}

$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;

[code]....

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;
$helper->test();
$this->render("home");
}

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?

Sep 21, 2009

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

Feb 9, 2011

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:

[Code..........]

View 3 Replies View Related

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

Jan 8, 2011

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?]
[Code]....

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

Sep 23, 2010

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?

Feb 9, 2011

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(
$this->getHelper('url')->url(

[Code]....

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?

Jun 10, 2011

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?

Jul 15, 2010

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?

Jun 7, 2010

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

Apr 13, 2011

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

Jun 21, 2011

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?

Aug 2, 2010

This is my basic file structure

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

[Code].....

And in routes:

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

Browsing to http://mywebsite.com/admin 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

CodeIgniter Load Controller From View?

Apr 29, 2011

Is there a way to load a controller from a view ? Here is what i am affter.. I want to use one view multiple times, but this view is being loaded by separate controller that gives the view, information from the db.So becouse of that information from the model i can't just set $this-load->view(); and etc. Is there a way to do this thing, or it has a better way ?

View 4 Replies View Related

Prefer To Structure Controller (s) In CodeIgniter?

Mar 5, 2010

I was wondering how you find it most easy to setup your controllers. Do you use one controller pr. sub-section of your site (ie. “Friends”, “Inbox”, “My account” etc.), or do you just use one controller that keeps all of the sub-sections?

View 1 Replies View Related

Determine Problem In CodeIgniter Controller?

May 4, 2011

I've created a base controller that all of my controllers extend...

class PublicController extends CI_Controller {
private $js = array(),
$css = array(),
$templateVars = array();
public function __construct () {
parent::__construct();
//register account
$this->templateVars['account'] = ($this->account = $this->modelFactory('account'));
// enable profiler for development..........

View 1 Replies View Related

In CodeIgniter, Default Controller Is Always Loaded?

Apr 27, 2011

I am trying to migrate my CI 1.7.2 application into 2.0.2. I have gotten to the point where my default controller and page are loaded correct. Yey!However, the default controller is all that’s ever loaded. Example:

myapp/ -> loads default controller (one)
myapp/one -> loads default controller (one)
myapp/two -> loads default controller (one)

[code]...

View 1 Replies View Related

Load A View In Every Controller In CodeIgniter?

Jan 9, 2010

Because I thought of ajax posting my form to a specific function in my controller and do a sql-insert, but I want to stay on the same page. So is it necessary to load a view in the posted url (=destination)?

View 1 Replies View Related

Refactoring Controller To Model In CodeIgniter?

Feb 1, 2011

It's come to my attention that my image processing code that I currently have in my controller would be better suited in a model, but I'm not sure even where to start to do this. I have a controller that handles uploading an image, renaming the file and storing it in the database using Doctrine:

<?php
class Addimage extends Controller
{
function index()

[code]....

I would like to be able to have most of this in a model, because I'm using a template system for the views where my uploadimage.php view is just the upload form so that it can be dropped on any page. Also, I only have experience using Doctrine models.

View 1 Replies View Related

CodeIgniter 2.0 Cannot Use Method Of A Model From Controller?

Feb 3, 2011

I'm trying to call a method of my model from my controller and I keep getting an error and I'm unsure as to what im doing wrong

PHP Version: 5.3
CodeIgniter Version: 2.0
/application/models/blog.php[code]....

Error Message: Fatal error: Call to a member function get_last_ten_entries() on a non-object

View 2 Replies View Related

Get Whole Post Body Within Codeigniter Controller?

Dec 2, 2010

I'm running XMLHttpRequest request like this:

var data = JSON.stringify({
name : "123",
id : 12[code]...

as you can see there's no name for parameter being passed.now I want to read that JSON data inside ipsum function of lorem controller.How can I do this? $this->input->post(); returns false :(

View 1 Replies View Related

Codeigniter Model Not Loading Into Controller?

Feb 1, 2011

I am having trouble with a models in Codeigniter. I setup a model called Usermodel in /models usermodel.php. and when I attempt to load it is stops the scrip and anything after it. When I purposely entered a wrong name in the ->load->model area CI throws up an error, saying it can't be found (like expected) When everything is correct nothing is loaded.

User model
class Usermodel {
function __construct()
{

[code]....

View 2 Replies View Related

Codeigniter Controller/model In Mysql?

Jun 18, 2009

<?php
class Sitemodel extends Model
[code]....

View 1 Replies View Related

Remove Controller Name From Url In Codeigniter With Routes

May 30, 2011

I know this has been asked a bunch of times, but I can't make it work at all. I'm trying to remove the index.php and the controller name (I only have one controller) from the URL. So far, I was able to remove the index.php, but I still can't remove the controller name Here is my htaccess file:

RewriteEngine on
RewriteCond $1 !^(index.php|images|static|robots.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]

Here is the top part of my config file:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['base_url'] = '/main/';
$config['index_page'] = '';

And I put this as my last line in my routes file:

$routes['([a-z\_]+)$'] = "main/$1";

I'm using BlueHost, and the site is an addon domain to that account. Not sure if that makes any difference. But as of now, I was able to remove the index.php, but I want to remove "main" as well.

View 2 Replies View Related

Access Controller Class In CodeIgniter?

Oct 9, 2009

I have written an authentication class controller containing a method to check login status of user, and redirect him to login page if he/she is not logged in.

I need to call this function from other controller methods to authenticate the user. What is a good way to do that?

View 4 Replies View Related

CodeIgniter _remap() Routing More Then One Controller

Jun 16, 2011

I try to create a url shorter, using CodeIgniter 2.I have 2 controllers 'main' and 'api'. For routing a short link to redirect I using this setting in config/routes and one method in main contoller exelent works, but any controllers can't start.

$route['(.*)'] = "main/$1";

View 1 Replies View Related

CodeIgniter User Profile Controller?

Jun 24, 2010

Why isn't this working? I'm trying to make a php user profile URL.

<?php
class Users extends Controller {
[code]....

Parse error: parse error, expecting `')'' in C:wampwwwsystemapplicationcontrollersusers.php on line 7

View 2 Replies View Related

ADVERTISEMENT