I've just given 5 interviews to senior developers and only one of them could answer this question.
What is the result of this function. <?php echo floor(3.1); Am I going crazy here?
In this archive from Apr 2010 to Jul 2017
What is the result of this function. <?php echo floor(3.1); Am I going crazy here?
$this->uri != $this->real_uri ? $this->need_redirect = false : eregi("(cName|pName|mName)", $this->uri) ? $this>attributes['SEO_REWRITE_TYPE'] != 'cName' ? $this->need_redirect = true : $this->need_redirect = false : ereg("(".implode('|', $pattern).")", $this->uri) ? $this->need_redirect = true : $t...
Hi there, I have a Canon 5D MK II, recently the pins became broken on the CF reader. I've sent it to be repaired and they've said it will cost 400 euros/ $550 to fix because it's my fault for not inserting the card correctly. As far as I can see, here is only one way to correctly insert the card. Do...
Hi everyone. I'm going to buy a Canon EF 16-35mm/ 2,8/ L II this week. I've seen a used one on Amazon Marketplace for about £419 ($660) less than the RRP. What are the risks of buying a used lens? Is it worth spending the extra $$$ on a new lens? Thanks for your help. Robin edit got the prices wrong...
I'm not that evil.
When I was starting out with MVC, no one explained it in a way I understood, I wish someone had written it out like this, (this is from a PHP MVC standpoint as per Cake, CI, rails): None of these examples will work in real frameworks they're just PHP psudocode.
Controllers.
Each controller is a collection of functions (aka actions or methods) called a class. The class' name usually relates to a database table, but not always. So for example, if you had a table in your database called 'page' in your database you might have a controller with various actions that a user can access related to that class (such as viewing, deleting and editing).
Your controller class has various actions or methods such as edit, view, delete etc. Each of these actions is a chunk of sub-code like any other function.
Example
<?php class page{ function view() { //view page code here } function delete() { // delete page code here } } Now, if you wanted to access the 'view' chunk of code on your 'page' controller, you would go to this url: www.yoursite.com/**page**/**view**/ That would tell your framework to load up the collection of blog functions then execute the one called view. You might have many different controllers with various actions within one website. Some frameworks offer an easy way to get variables into your code via the url. Let's say you wanted to load a page based on an database ID supplied within the url. In this example the ID is 31234 www.yoursite.com/**page**/**view**/31234 <?php class page{ function view($page_id) { //now we have a $page_id varibale which we can use to select certain stuff from the database } } Controllers never have direct database related code or html within them. Controllers are to react to user interaction (in this case sending of a url, but also cookies and GET/POST data) and based on that user information access various parts of the application such as database stuff (via a model, which we'll come to later), then pass that stuff into the views (we'll come to that later). GET,POST and URL stuff should only ever be accessed within the controller. **Models** Controllers sometimes are related to database tables. Models, almost *always* pertain to database tables. If we carry on with the 'page', example, i'll give you an example of a basic model. Again this is basic, pretend code. <?php class page_model{ function get_from_id($page_id) { $database->query("select * from pages where id=$page_id"); return $database->result; } function delete($page_id)) { $database->query("delete from pages where id=$page_id"); } function get_all() { $database->query("select * from pages"); return $database->result; } } As you might be able to tell, the model is just a set of actions related to manipulating a certain type of data. In this case we're manipulating a database table. Models should never have HTML or access GET or POST data. Models should be the only place you access your database from in your application specific code. **Models and Controllers** This is how the relationship between a model and controller might look. <?php // this is our controller class page{ function view($page_id) { $page_data=Page_model->get_from_id($page_id); } } If a user went to the url www.yoursite.com/page/view/453 Firstly the page controller would be loaded, then the view function would be executed with the variable from the url (453) set as a parameter. Then the parameter passed into the page model and the page database record returned. **Views** Views are your presentation data, mostly HTML. Views should never access the database or models. Views should never access get or post variables or cookies and should only contain the most basic of PHP functionality such as echo and loop control structures. I don't really need to show what a view looks like because it's just HTML and PHP, but here's an example of what one might look like <!-- a_lovely_view.php --> <title><?php $page_title;?></title>The final part of the jigsaw is to get variables from the controller, into the view
Models, Controllers and Views*
So if our user went to
www.yoursite.com/**page**/**view**/1234
the result would be
I hope that simplifies this for you. As an absolute beginner, I'd suggest CodeIgniter because its very, very simple.
A couple said simply I don't know and the others said they'd seen it but can't remember.
For me this isn't a live or die question but I wanted to warm them up with some softball questions to get their confidence up before the harder questions came,.
Oh god: it is just as hideous as the old site but with more usability issues.
Things I'd love to see implemented in the near future.
Ability to hint to methods/functions. To avoid stuff like: createimage(null,null,null,null,null,100,100); and allow: createimage([x:100,y:100]);
A String object.
A way to create short object
$hello={'name':'robin','age':12,getWeight:someCallback}; echo $hello->name;