How to develop mobile application using CodeIgniter? - codeigniter

I wanted to develop the mobile application using CodeIgniter. Is it possible.
Web application is already built on CodeIgniter

You'll have to create a new controller and add appropriate routes. When I had to do this, I just used a controller that inherited from my primary site controller and added these routes to my routes config (Mine was located in /system/application/config/routes.php. Yours also may look different and this code snippet assumes you have a page function):
$route['mobile/(:any)'] = "site/mobile/page/$1";
$route['mobile'] = "site/mobile/page/home";
Then you'll want to add a rule to your htaccess file to ensure anything going to m.example.com/whatever gets directed to the right path (e.g. /mobile/whatever).
RewriteCond %{HTTP_HOST} (^mobile\.|^m\.)(.*) [NC]
RewriteRule (.*) /index.php/mobile/$1 [L]
From there it should route into your mobile controller. Form me this was in /site/controllers/mobile.php. My primary site controller was /site/controllers/site.php
You'll want to recreate whatever logic you use in your site controller in you mobile one excluding desktop assets and including mobile ones and rendering your pages appropriately. Unfortunately that's about all I understand of the process. It was mostly my coworker's work that got the mobile controller working and I only used it once or twice, but this should work.

Yes, it is posibble. It all depends on your strategy. If you decide to go with Responsive Design, codeigniter makes no difference. If you decide on Adaptive you shoul read the about codeigniter's user-agent library -
https://ellislab.com/codeigniter/user-guide/libraries/user_agent.html
To read about RWD and AWD visit http://www.techrepublic.com/blog/web-designer/what-is-the-difference-between-responsive-vs-adaptive-web-design/

Related

How routing is done in codeigniter?

I could not find the .htaccess file in CodeIgniter framework and i'm wondering how do they do route without it? Or it is somewhere hidden?
There is no .htaccess by default provided with codeigniter. They serve it through the index.php. .htaccess is only used to direct the urls to the index.php. This way codeigniter is working in environments where rewriting isn't allowed. Another way of getting controller and function is by query strings.
Anyway the actual routing is done in system/core/Router.php so you can read the code. Since Codeigniter is open source application that can't be hidden.

joomla rename component url using htaccess

I'm building an eshop using Joomla 2.5 and a commercial component for a guy who wants to have multiple vendros and I'm stuck on how to change the component's url.
What I want to change is the url that is displayed when the users passes from a link with his mouse.
For instance, the component has a SEF function which rewrites urls and makes them like that:
http://www.site.com/componentname/products/productname-productid-productcategoryid-vendorid.html
http://www.site.com/componentname/catalog/categoryname-categoryid-numberofpage.html
and what I want is to make it:
http://www.site.com/shop/products/productname-productid-productcategoryid-vendorid.html
http://www.site.com/shop/catalog/categoryname-categoryid-numberofpage.html
So when a user passes over a link it will show him the new url. Is this possible with .htaccess and rewrite rules or this can only be done through the component only? I'm asking this as the component is encoded with ioncube so I can't do it myself.
Thanks in advance!
While you can use .htaccess to rewrite any URL it won't work with Joomla! as the SEF URL is created by JRoute which uses a combination of the core route function and the route.php for the component.
The URL segments are used to find the right component to handle the request, so to change the way the URL is built you would have to modify the route.php of the component (and obviously other parts as well).
For more information on how SEF support works, read this on docs.joomla.org

Apache Redirect on downstream 404

We are building a mobile site whose url structure matches our current desktop site. We are hosting them on the same domain, and using apache to filter traffic between them using WURFL to help decide which agents go where.
Our filtering rules currently look like this:
RewriteCond %{HTTP_COOKIE} "bucket=mobile"
RewriteRule ^(.*)$ http://internal-mobile-pool.ourdomain.com/$1 [P]
RewriteRule ^(.*)$ http://internal-desktop-pool.ourdomain.com/$1 [P]
Our WURFL based solution sets the 'bucket' cookie for us.
The problem we are facing is that not all the urls on our desktop site have been re-implemented on our mobile site. What I would ideally like, is for the above rule to apply, but if it tries to go to the mobile servers, and gets a 404, it serves up the content from the desktop servers instead.
ie If a mobile requests www.ourdomain.com/some_desktop_only_resource.html, and the internal-mobile-pool.ourdomain.com/some_desktop_only_resource.html returns a 404 - for it to return the content on desktop-pool.ourdomain.com/some_desktop_only_resource.html
To describe this in pseudo-code
if(isMobile)
response = getMobileResponse(url)
if(response.code != 404)
serveResponse(response)
else
serveResponse(getDesktopResponse(url))
I know this is possible if I list all the supported urls in this file - I would like to avoid this, as I would like this Platform Recognition layer to be independent of the application it serves. I also know I could solve this in the mobile application itself by redirecting from there, but if at all possible, I would like this Platform Recognition layer to be self-contained.
Is this possible using mod_rewrite?
Don't think there's a way to do this using mod_rewrite. Because you're using the [P] flag to proxy, the RewriteRule hands the proxy request to mod_proxy and doesn't even know if it went through or not. If everything was in the same document root (or at least subdirectories of the document root), you'd be able to use the -f conditional check to see if a file exists.
Something you could try doing, though I have no idea if this will work, is using mod_proxy's ProxyErrorOverride along with ErrorDocument. If your ProxyErrorOverride is turned on, theoretically if a proxied request returns an error, mod_proxy will use the local error handler instead of the proxied one. You could then use a ErrorDocument 404 to handle the proxied 404 with a php script or something, then do something about re-routing it back through the local rewrite engine (with maybe a redirect with a special query string param?) so that it could be proxied to the desktop domain.

Whats the purpose of Index.php in MVC Frameworks?

I want a good understandable description of index.php in MVC Frameworks... I have worked in Magento and Codeignitor...
In Magento URL's index.php is called front controller but in codeignitor what it is?
Plz clear the concept of index.php in MVC Frameworks?
The index is your entry point from where it will dispatch / route your URL to the appropriate controllers/actions. You don't have to name in index.php though, you can give it whatever name you want, as long as you call the file, it won't be a problem.
In codeigniter index.php is the entry point of the application. Its not a controller. It sets your environment, initializes your config/route/autoload etc. and then loads your requested controller.
Generally, index.php mainly works as a bootstrapper. It initializes all most variables and puts your application in a usable state. Almost all calls are routed through it. If you want you can also hide index.php from your visible path using .htaccess. For example in yii you can use this guide: http://www.yiiframework.com/wiki/214/url-hide-index-php/

URL Rewrite to remove my controller's name from the url displayed

I have this site
http://cjbuilders.info/welcome/home
and all the links start with
http://cjbuilders.info/welcome
How can I use mod_rewrite to just remove
/welcome/
from the url? This should be an easy one, but i struggle with mod_rewrite.
Do you know about CodeIgniter's URI Routing? Add this into your routes.php config file and it should work just fine:
$route['home'] = 'welcome/home';
This should work, IIRC:
RewriteRule ^/welcome/(.*)$ /$1 [R]
However, guessing a bit about what's going on here, if the reason for this prefix is something like a Java app server deploying an app at a context called "welcome", then the better solution is not to rewrite the URLs but to fix the backend app server to have a null context, i.e. serve at / rather than at /welcome/.
This is because the app server will probably want to generate links to other views of its app, and will reinsert the "welcome": this becomes a pain, and means that all links on your pages will get HTTP redirects when visited (e.g. by search engines). There is no way that the proxying apache server can parse the HTML and tell when that "welcome" should be removed, so best to fix the server that's writing the links in the first place.

Resources