Welcome Guest, Not a member yet? Register   Sign In
Another View Hurdle
#1

[eluser]escape[/eluser]
I've been, for some time, trying to find a good way to integrate standard web page designs into the CI view hierarchy. For the most part I had to resort to various hacks to make web pages display correctly without breaking links to assets within the page. Although I've got a process to make this work I'm hoping others in the CI community can recommend a better approach.

Here is the workflow I'm faced with. A web designer creates a set of pages which will represent the look and feel of the application I wish to create with CI. The designer, who doesn't know anything about CI, creates the pages with relative references to all assets. I copy the pages to the CI view directory where they will be used in conjunction with CI's template parser class.

Without any modification CI will display the assigned template pages however all asset links will be broken. This situation can be overcome by inserting the html base tag in the head of the template page
Code:
<base href="{base_url}" />

where {base_url} ($config['base_url'] = "http://127.0.0.1/CI/";) is assigned in my controller (mycontroller.php) as follows:
Code:
function index() {
$data = array(
    'base_url' => base_url() . 'system/application/views/',
    'content' => 'Some Content I wish to display'
    );
$this->parser->parse('mypage.htm', $data);
}

This arrangment appears to work fine until I need to call a function within my controller. For example my page may have a form where the action references a controller function like:

Code:
<form action="mycontroller/a_function" method="post">

When I submit this form CI routes the post to:
http://127.0.0.1/CI/system/application/v...a_function
which throws the Object not found! error because CI is looking for the controller in the views directory.

To rectify this I must re-factor the form action to:
<form action="../../../index.php/mycontroller/a_function" method="post">
I don't know if this is appropriate or if I will run into other problems in the future. I'm hoping other more experienced CI developers will be able to advise me on a better approach.
#2

[eluser]philpalmieri[/eluser]
Hey escape,

Maybe im just over simplifying your problem, but first: the 127.0.0.1 is coming in because you havnt set $config['base_url'] in your config.

Next up, is instead of posting to a relative action:
Code:
<form method="post" action="mycontroller/a_function">

have them use absolute path..(notice the pre-pended '/')
Code:
<form method="post" action="/mycontroller/a_function">

Also, you can do some simpe .htaccess stuff to get rid of the index.php too.

if you dont want to mess with .htaccess
Code:
<form method="post" action="/index.php/mycontroller/a_function">

Phil
#3

[eluser]escape[/eluser]
Quote:where {base_url} ($config[‘base_url’] = “http://127.0.0.1/CI/”;)
I'm still in development on localhost so I think 127.0.0.1 is appropriate.

Thanks for your absolute path recommendations but none of these will work because the html page has the base tag set which controls page assests as well as form actions.

Unfortunatly .htaccess is not an option.




Theme © iAndrew 2016 - Forum software by © MyBB