What kind of code will controllers have?
The code for data input and output is in the Controller. In other words, it's ok to run validation of input parameters from the form in the controller; indication of the data type that are given (e.g.
JSON) – it’s also fine. But running different operations with data inside the model – it’s not a good approach, because they should be in the model itself.
How can a controller coordinate with blocks and know where to display?
such as code like this (code not to be indexed), it is totally alien code to me, how can i understand it? How does it connect to our view or block type?
The Layout (not the Controller) is responsible for displaying blocks. Hence, it is completely incorrect to write
die($data) to get data. So, working with such data volume should be shifted to the separate modules or the helper (if it has something in common). You should specify in the layout how and where to display a certain block and what data (template for example) should be used. Thus, this data may be specified directly in the class block or in the controller during the work with layout.
How does the code above will have connection to the database?
Your code is communicating with database through the model, that have its own resource model with established connection.
$billingAddress = Mage::getModel('customer/address') is used to call the model, but
$model->save() will call resource model to save data.
What does entities mean? Any real life example. Is that all what is needed to make a connection to database, how does magento insert data into multiple table at once if that is the format.
Entitles mean a certain table (data) to use with this resource model. In fact, this is the name of the table. If you need to fill out multiple tables with data, you can realize it on the resource model level for model that you are saving or updating. For example,
Mage_Catalog_Model_Resource_Product: after saving the method
_afterSave is called and the method
_saveWebsiteIds is called inside it to save additional data:
//Save product website relations
$adapter = $this->_getWriteAdapter();
From this part of code it is clear that another table is used. It is quite a normal practice, when you are working with difficult models like product, that has different dependencies.
How can i connect a event with a task?
Use the observer for your event. In addition, you can place events in your code to use them in future modules. Here you can read the example:
How can i know the method name build into magento e.g getTitle(''); etc
Usually, in Magento such methods are somewhat “magical”. They are:
uns (unset). If in the object and its ancestors is clearly no such a method, then the method
$object->getData('title') will be called. If your method looks like
getSomeImportantTitle() then it will be called
$object->getData('some_important_title'). To better understand how it works, I suggest using phpStorm and wonderful plugin for M1 - Magiciento (he teaches phpStorm to understand Magento). Also, it adds a number of useful features, that I never used.
How do i know about to make a custom layout, ...
It is simple to understand the layout. There are location and content. If you call
getChildHtml('left’) then its too late to change something in the “left”. You should take care about this in the layout and add the required data and checks. If your block shouldn’t be displayed on the all lefts, then it should be entered not in the
<default> area, but only in the desired one, for example
<catalog_product_view>. You should study Magento standard layouts. It’s not difficult to understand them. Note, that the layout of the customer account page, for example, can be updated in any other module. Layouts also have the ability to change the behavior of the blocks using the
<action method="methodName"> – in fact this is the call of block method (that is inscribed in the action, its parent). Parameters can be transferred to actions inside.
getChildHtml() can be used only in case when you want to add the contents added via layout in the specific place. In this case, any developer can add a child to your unit and its contents will also be displayed in the template.
How do we map data outputted from a db to a form e.g a form that has input fields and i need to populate data into it.
Use standard features Magento such as
varienForm with validator. But the form itself should be manually drawn (written in html) by yourself in the template. There are a lot of options to work with forms in the admin panel. There is a fieldset for connecting the model and view. It has a lot of opportunities, but I can write a lot about it and it exceeds the possibilities of this answer. You may read some information here:
- Module Development Series – Magento Admin Module – Part4
- Magento admin form fieldset custom type
How do i make custom menu for my own page and link to different that display different data
The admin panel has a separate file for menu
etc/system.xml. You can see the example of the same module
Mage_Catalog. When you are working with menus on the front-end, you need to use the unit in this menu and its methods. Here is the example:
<block type="core/text_list" name="top.menu" as="topMenu" translate="label">
Standard menu is the block
Mage_Core_Block_Text_List, that displays each child. To add something, you can assign your own child to this block in the layout and data should be displayed without problems. But in each case you need to study how it works.
I hope this information would be useful.