Welcome Guest, Not a member yet? Register   Sign In
Mobile website, how to approach?
#1

[eluser]Sinclair[/eluser]
Hi,

I have a website running in CI, and now I need to develop a mobile version of the website.

How should I develop the mobile website?

I need to have an URL like "www.website.com/mobile". My doubt is, should I start a new CI project, with all the files anf put them is the folder "mobile" or should I work in the current project, making a new controller called "mobile"?

Give me some clues on how should I do?


Best Regards,
#2

[eluser]rogierb[/eluser]
Create a new application directory called 'mobile_app'
Create a mobile directory where you put a index.php that has mobile_app as the application

In you .htaccess in 'mobile' do the usual stuff
in your .htaccess in 'root' route to 'mobile' (RewriteBase /mobile/)

Or something like that...
Unless you want the mobile app to use the files from the 'old' app. Then i would go for HMCV.
#3

[eluser]Sinclair[/eluser]
Thanks for your reply.

What is the definition of HMCV?

Best Regards,
#4

[eluser]rogierb[/eluser]
Ah typo, should be HMVC..

Take a look here, one of the contributions in the wiki.
http://codeigniter.com/wiki/Modular_Extensions_-_HMVC/
#5

[eluser]Unknown[/eluser]
I would go about this a different way. I am assuming that you want to share the logic between your web and mobile versions of your site, but just render it differently depending on which version users are accessing. This may be WAY overkill depeinding on how complex your app is.


1) Create a base class controller library that extends the CI_Controller class

2) Add a protected variable to this class called $display_version

3) Add a protected function called render in this base class which displays either the mobile version of the page, or the web version depending on the value of $this->display_version. Default this to the web version. The function signature of this render function should match that of the $this->load->view() exactly. In this render function, add the $display_version to the $data array before calling the $this->load->view()

4) Make all of your standard controllers extend the new library that you just created

5) Update all of your controller actions to call $this->render() instead of $this->load->view().

6) At this point you should be able to test your site and nothing should see no change

7) Create the following folder "/controllers/mobile"

8) Create controllers in the mobile folder that extend the regular controllers. You will have to name these controllers mobile_* because you cannot have a class extend another that has the same name (A class named "products" cannot extend another class named "products")

9) In all of the mobile controller constructors set the $this->display_version = "mobile" before calling the parent::__constructor();

10) Setup routes(s) that map calls to "/mobile/products" for example, to "/mobile/mobile_products". You can probably do this with one RegEx, or you can create one for each contoller.

11) Override the anchor() and form_open() helper functions (there are probably more), to build their URLs to include the "/mobile" path depending on the value of $display_version (this is why we have to add it to the $data array when calling the view)


The advantage to this method is that you really only need to build your web controllers and you don't need to duplicate any controller code. Once the web version is setup you just have to worry about creating the different versions of the views. In addition, if there are any mobile specific functions that you need to add, or changes to the default controller behavior, you can do that in the mobile_* versions of the controllers.

Like I mentioned, this may be way overkill, but just throwing it out there.
#6

[eluser]Eric Cope[/eluser]
detect user agents and include different css?




Theme © iAndrew 2016 - Forum software by © MyBB