Codeigniter Loading external site in default controller - php

I'm not able to figure this out on my own so here I am asking for your help.
How do I load a website that I already made as a view in the code igniter default controller?
I put my website under a folder name site, and in the default controller I loaded the view site/index , but then in my site there are problems with the includes and redirects... I don't know why, I guess the way the site usually works with redirecting isn't compatible with code igniter style
edit: I guess I would have to turn off CI engine for this site, but I don't know why, because I would still need codeingiter to manage other parts of my application

"CodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes.php file and set this variable:
$route['default_controller'] = 'Blog';
Where Blog is the name of the controller class you want used. If you now load your main index.php file without specifying any URI segments you'll see your Hello World message by default."
http://codeigniter.com/user_guide/general/controllers.html
fragment copied from that link , you should put the controllers classname in that config, not the view

I guess it's better to choose one of these options:
Modify the existing site to a CodeIgniter site.
Keep your site separate from the CodeIgniter site, and just link between the two sites.
The way you are trying to do it seems very useless and causing a lot of extra trouble.

You can simply use the redirect function in your controller. If you supply a full URL you can go to any other page. You will, of course, leave your CI app.
redirect('http://www.example.net/page_in_external_site/');

Try using the APPPATH constant when defining the paths for the includes.

I know it's an old question, but you can try using a view template with an iframe, and you can pass the URL to the src property of the iframe. That way you can display your site inside a view, but still can't get access to the vars passed to the view from your site.

In system/Core/Loader.php change the line 141 to look like this:
$this->_ci_view_paths = array(APPPATH . 'views/' => TRUE, FCPATH => TRUE);
and to get the view is simple:
$this->load->view('application/ PATH_TO_VIEW');

Related

webroot entire path in Yii2

I have some trouble with an Yii2 application.
I need to put into a variabile the complete webroot path of my application, in my case www.mysite.it/language/catalogue/. When I call the function to retrieve this information, I get www.mysite.it/application/web where application/web is the root of my project.
I have tried this function:
$home = Yii::$app->request->getAbsoluteUrl();
It is any way to do what I want?
Thanks in advance.
You should use yii\helpers\Url features
http://www.yiiframework.com/doc-2.0/yii-helpers-url.html
http://www.yiiframework.com/doc-2.0/guide-helper-url.html
and eg_ for home Url::home()
$absoluteHomeUrl = Url::home(true);
or for Url:to()
$url = Url::toRoute(['language/catalogue/']);
the use of the UrlHelpers prevent your code from different url result related
to your urlManager config (with or without pretty url)

PHP CodeIgniter URL navigation issue

I am new to CodeIgniter and also have average PHP knowledge. Just started learning CodeIgniter last week and having a basic problem which i can't overcome. my development environment is (OS,PHPStorm,MAMP,APACHE). CI project root is http://localhost:63342/CodeIgniter/ and this address loads my 'default_controller' (login.php in Controllers folder). this controller redirect me to my view "$this->load->view('login_view');". in my view i have a form with this line: which supposed to take me to my form.php in Controller upon the form being submitted but it does not! when i submit i am taken to a url : http://127.0.0.1/CodeIgniter/form with error message "connection attempt to 127.0.0.1 was rejected.".
Also when i try to type a url (i.e. BASE_URL()./index.php/form) or amy other URL in fact, i get errors too. i was under impression that navigating through pages in CI is as simple as typing the name of the file and the method in it in my Controller folder. what am i missing here? any attempt to navigation through URL i get "404 Not Found" error. i am sure i am missing something very simple here but i can't figure out what. i have read the documentations and search the web and no answer is found. i have changed the .htdaccess in root, tried the enable mode in Apache, done all the necessary changes in Config.php , routes.php etc. i would appreciated it if you can tell what am i doing wrong here. i wasn't expecting getting started with CI to be this hard :s
cheers
It seems you "loose" the port (63342) when you redirect. What is the action of your form? If this is an url like "http://localhost/CodeIgniter/form", you should add the port : http://localhost:63342/CodeIgniter/form
You can output set your login form's action by using the URL helper.
site_url('form')
http://www.codeigniter.com/user_guide/helpers/url_helper.html?highlight=site_url#site_url

Problems reading data from Codeigniter Template Partials, and with controller redirection

I have two unrelated Codeigniter problems:
(a) I am trying to redirect a user to the dashboard after logging in successfully. i.e. from controller "auth" to controller "dashboard". For some odd reason, it keeps redirecting to auth/dashboard (404 error since it does not exist).
This is what I did:
//Within the auth controller
if ($this->auth->login($username, $password)) //Auth->login returns boolean
{
redirect('/dashboard', 'refresh');
# redirect('/dashboard', 'location'); // I tried this too
# redirect('/dashboard/index', 'refresh'); // I also tried this!
}
What am I doing wrong, please? It just keeps redirecting to auth/dashboard
(b) I am using Phil Sturgeon's brilliant Codeigniter Template library (without a Parser) and I am unable to receive data sent into a partials file. This data is ONLY needed by the partials file. I have been over the (unfortunately sparse) library documentation, S/O posts on the topic, and also the CI forums to no avail, there seems to be no clear-cut example showing how a partial receives data that a controller assigns to it.
This is how I have been doing it. Please tell me what I must be doing wrong.
// In the controller page
$this->data['user'] = array('info' => 'username', 'value' => 'Cogicero');
$this->data['prefs'] = array('foo' => 'bar');
$this->template
->set_partial('header', 'partials/header', $this->data)
->set_layout('blog')
->build('foobar_view');
And
//In the header partials page
<?php
/* snip */
print_r($data);
print_r($prefs);
print_r($user);
echo $user["info"];
echo $prefs["foo"];
?>
All the above produce "array does not exist" or "undefined variable" errors! How am I meant to be receiving data within the partials view file?
Thanks
EDIT:
Working on a tight deadline so with no solution in sight, I had to abandon Phil Sturgeon's template library and pick up Jens Segers' instead. http://www.jenssegers.be/blog/25/Codeigniter-template-library
It is a little similar to Phil's but for some reason the partials are receiving and rendering my data properly. Also, Sergers' template library is very well documented. All is fine now, so I'll accept my own answer to problem (a). Thanks everyone.
(a) So after a lot of fiddling around I have solved the first problem i.e. the redirects.
In the config file, we have
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url']=
Apparently, I didn't set a base URL because I'm still on a development local server, I was going to set it to the www address when I upload to the test server. Codeigniter had been guessing all along, but the guess didn't work for my authentication redirects. I set the base url and all redirects were fine.
(b) Now, to see why the partial views are not receiving data. Any help please? :(

Need help with Code Igniter [did not found page created]

so I hope someone would help me.
My first page is leave_app.php. In this page I put a link to apply leave, using the normal code:
New Leave Application
However the link didn't display as I had wished for.
"The requested URL /ci/add.php was not found on this server." and the link in the browser leads to this "http://localhost/ci/add.php".
I don't know why the server didn't find the page. I already made add.php page, also add at the leave_app controller the function add().
In the config.php file I put $config['index_page'] = '';
I have asked around but no one can help. I have already surfed around, but still don't know how to solve.
The beauty of Codeigniter is to rewrite urls in a clean manner, so all things go through index.php and the corresponding controller is loaded
Try accessing it like so:
/ci/index.php/add
Make sure your controller is in application\controllers\add.php and named Class Add

codeigniter, global variable for beta project path, and access from everywhere

I use CodeIgniter, I'm happy with that, but I have a question.
I build my projects under /www/projectname/beta/... directory, so at my code, at many parts like including some images or css files or etc. I have to make ... src="/projectname/beta/... so when I complete the website, I need to edit so many pages to clear these /projectname/beta/ path and make it / for main root. or when I start new project with same base, first of all I need to edit these paths at all files.
now, how can I define a variable like
$projectbetapath =
"/projectname/beta/";
and have access from everywhere, like global. where can I add such line, and how can I access this var from everywhere?
Thanks!! appreciate!
Why don't you add a constant in your index.php file?
define('BETA_PATH', '/beta');
When the site leaves the beta stage you just do:
define('BETA_PATH', '');
There are two answers to your question:
Set your variables as array fields of $config in application/config/config.php and access them with $this->config->item('name');
Use the URL-helper (Or $this->config->item('base_url')) to get the current base path whenever you have to type in a path.
The second answer will give you full flexibility, you'll only have to modify the base URL in config.php if the project moves.

Categories