Welcome Guest, Not a member yet? Register   Sign In
How To Go About This
#1

[eluser]Matt Egan[/eluser]
I'm working on my Technology Fair project, its a CI photo gallery where you'll be able to upload photos, and make comments on individual photos. I also plan it to have Albums. I've got my custom configuration files all set up, and I've got my databases laid out. But before I actually start writing my Controllers and Models, I've got a couple questions.

One.

Would I be better off just randomly creating a thumbnail for each photo, or should I have some sort of javascript that allows the user to crop and resize the photo for the thumbnail. Then it could pass the numbers onto Codeigniter's image manipulation class.

Two.

Should I even use the same size thumbnails? I think that photo galleries with unevenly sized thumbnails are pretty ugly. (I'm also looking at this from a design standpoint)

Three.

How much should the model do? I'm really kind of confused about this. Should my model actually make markup? For example, when I pull all of the photo data out of the database, then go ahead and produce some HTML then just output the created variable as a string into the View?

Four.

I'm kind of confused as to where I put my images and Css files. I've extended Derek's video tutorial to give the blog some styling and a little simple back-end administration panel. I've had success just putting the photos in a folder named static inside my Application folder, but then whenever I want to insert a photo or Css file I have to use base_url() and then add the rest of the URL. Is there any simpler way to do this, am I missing anything?

Thanks for all the help. I plan on releasing this after the tech fair, which is in a couple months, I should have a ton of time to work on it now that it's Winter Break. So, I'll put up a little demo when I feel like its ready. You guys seem really helpful, and I'm looking forward to the feedback!
#2

[eluser]garrettheel[/eluser]
I'll help answer what I can..

The model is usually the "heavy lifter" of the application and generally deals with the database interactions. But I also assume you would have your image manipulation functions and such in a model. Essentially, the controller is only supposed to tell everything what to do and send the right information to the right place, so you don't want to be doing anything big in the controllers.

For example, if you are adding a new image, you might have the controller send all of the data to the correct model (e.g $this->image_model->add_image()) and then redirect the user to the new photo if it is successful or load an error view if there is something wrong. That should probably be the extent of the controllers job. It is then the models job to do the image manipulation and database interaction. As for the validation, maybe someone more experience can comment on whether that should be done in the model or the controller?

For image and css files, you'll want them in the webroot of the application. So, in the same folder that system is, create some new folders (one for css, one for images, one for JS, etc.) and put everything in there. Also remember to change your .htaccess to allow these folders if you've added one to remove /index.php/
#3

[eluser]Colin Williams[/eluser]
Hey Matt. I think Garrett's guidelines are spot on. Controllers are the brains of your app, models do the hard labor, and views wear black turtlenecks and speak in fake accents. Your model should not generate markup, just data. Leave it to your view files for that. And when you want to abstract HTML markup output, I recommend using helpers.
#4

[eluser]Matt Egan[/eluser]
Thanks, that answers a lot of my questions! I think for the image thing, to resize the image until the smaller of the image is equal to 200, then the user will have a 200 x 200 box to drag either up or down or left or right.

One more question.

Is it bad practice to call a model function directly from the view?
#5

[eluser]Colin Williams[/eluser]
There are Passive Models and Active Models: Models that are unaware of their role in the MVC triad and models that update Controllers and Views of their status using an Observer pattern, respectively. Neither patterns suggest letting the View directly access the model. The latter, Active Models, allow for it via the Observer pattern (you only get Model updates, you don't alter the state of the Model). For the web, because of its stateless nature, it is generally recommended that you use a passive model.
#6

[eluser]Marcelo Kanzaki[/eluser]
When you're building a web application its a good idea to start coding with a minimal planning. Just the necessary.

Then, as you test and use the app, you'll get a better idea of what should be done differently in terms of code and design.

Should the images have the same size? Maybe. Or maybe not. See how they look when you have 30 rows to display. My opinion is that they should respect the original ratio. Go to Flickr, and Google's images search for inspiration.

Get it out there as soon as you can and let the users tell you what to do!
#7

[eluser]Colin Williams[/eluser]
The scale or crop question depends on the audience. If it's for photographers or stock photography, you can't really break the integrity of the image by cropping it.
#8

[eluser]jalalski[/eluser]
[quote author="Matt Egan" date="1229830896"]Should I even use the same size thumbnails? I think that photo galleries with unevenly sized thumbnails are pretty ugly. (I'm also looking at this from a design standpoint)[/quote]

This sounds like an excellent opportunity to create a function 'create_thumbnail()' and encapsulate the logic in there. Then if you need to change things later on, that is the only place to change.
Or, if there is more involved, create a library module that handles the images for you.

[quote author="Matt Egan" date="1229830896"]How much should the model do? I'm really kind of confused about this. Should my model actually make markup? For example, when I pull all of the photo data out of the database, then go ahead and produce some HTML then just output the created variable as a string into the View?[/quote]

The Model should handle the data needs of the application. I wouldn't put the thumbnail creation, nor the markup creation there. That sort of stuff is application logic and belongs in the Controller (or the library if you follow the previous suggestion). The Model will handle the loading and saving of your images and provide you with a standard API to the data models, which shouldn't really change much as the application develops.

HTH
#9

[eluser]Matt Egan[/eluser]
Wow! Thanks guys, this should really help.

@jalalski

Could I put the create_thumbnail function in the controller, and then call that function from inside the controller? Or would I be better off just creating my own photo processing helper with all my functions that deal with the photos in there?

@Collin and Marcelo

Thanks for all the help, yeah, I think ill go ahead and start and not worry about the little nitpicky details quite yet.

Thanks guys!
#10

[eluser]Henry Weismann[/eluser]
The way I code, and my understanding of the mvc pattern, is that all the business logic is in the controller, all the operations on the storage device (database) is done in the models then finally all presentation logic (html) is in the views.

My models never do anything except create and run queries on the database. My controllers do all of the work and the code in the controllers apply only to the application I am creating. Usually in my controller I will do things in the following order:

1. Load any libraries that that page will need.
2. Set up validation rules (Learn the validation library and life will be much easier!!!)

3. Handle successful validation or failed validation
4. If successful then manipulate your data first the send to a model to be saved to the database or save it to disk if it is a file. Then load the success view.
5. If failure load the failure view with an error message.


Codeignitor has a file upload library and a library for manipulating images. If these libraries does not do everything you need them to do you can extend them by putting a "sub class" in your libraries folder. See the bottom of the Creating Libraries page in the user guide. You can even create your own separate library if you feel the need. Libraries, in my understanding, usually include functionality that can apply to any application.

You can also create helpers but those should for the most part be single functions that don't need to interact with the system or other functions to be useful. These helpers can be specific to your application but I find that most of the helpers I create are useful in all applications I build.




Theme © iAndrew 2016 - Forum software by © MyBB