简体   繁体   English

从另一个URL向Joomla模块传递值

[英]Passing value to Joomla Module from another URL

I'm newbie to Joomla module development, and would like to implement a custom module for Joomla CMS. 我是Joomla模块开发的新手,并且想为Joomla CMS实现自定义模块。

I need to display the sales history of the logged in user. 我需要显示已登录用户的销售历史。 For example, a user with [username] = "US001" logged in successfully, and go to view what sales orders have done by him. 例如,一个[username] =“ US001”的用户成功登录,然后查看他的销售订单。 And the module display the data recordset in table format by passing the "US001" as username parameter to my database and retrieve the data. 然后,该模块通过将“ US001”作为用户名参数传递给我的数据库,并以表格式显示数据记录集并检索数据。

  1. How do I detect the user logged in and then remember the [username] for the whole session? 如何检测已登录的用户,然后记住整个会话的[用户名]?
  2. How can I pass this [username] parameter, eg "US001" to my external URL for retrieving data record set? 如何将此[用户名]参数(例如“ US001”)传递到我的外部URL,以检索数据记录集? My database for every user's sales history is in another different IP's server. 我用于每个用户销售历史的数据库位于另一个不同的IP服务器中。
  3. After query the data, how to return back my dataset to the module and draw my table out on that module? 查询数据后,如何将我的数据集返回到模块并在该模块上绘制表格?
  4. Additional function would be Admin's user able to control which field to be display, eg. 管理员的用户可以控制显示哪个字段,例如附加功能。 'age', 'e-mail', etc on the table in module. 模块表中的“年龄”,“电子邮件”等。

You want to access the user object. 您要访问用户对象。 Joomla already has most of what you need built in, you just pull up the current user and you have the info. Joomla已经内置了您所需的大部分功能,您只需拉动当前用户即可获得信息。

To start with, you will need to get the current user info - 首先,您需要获取当前的用户信息-

`$user =& JFactory::getUser();`
  1. if ($user->guest) will tell you if the user is logged in, $user->name will give you the username if ($user->guest)会告诉您用户是否已登录,则$user->name将为您提供用户名
  2. You will have to pass any info from Joomla to the external URL using either GET or POST. 您将必须使用GET或POST将任何信息从Joomla传递到外部URL。 Easiest way is to pass it as part of the URL query string (GET) external.url.com/database-page.html?username=name; 最简单的方法是将其作为URL查询字符串(GET)的一部分传递。external.url.com/database-page.html?username=name; ?> or similar ?>或类似
  3. Again, GET or POST the values you want to use back to the page containing your module. 再次,将要使用的值获取或发布回包含模块的页面。
  4. Not sure what you mean here, but it sounds like you need to add parameters (called form fields in 1.6 and newer) to your module so you can turn on or off the display of some of the data the module will be getting. 不确定您在这里的意思,但是听起来您需要向模块添加参数(在1.6及更高版本中称为表单字段),以便您可以打开或关闭模块将获取的某些数据的显示。

User object tutorial - http://docs.joomla.org/Accessing_the_current_user_object Parameters - http://docs.joomla.org/Standard_parameter_types Form fields - http://docs.joomla.org/Form_field 用户对象教程-http: //docs.joomla.org/Accessing_the_current_user_object参数-http: //docs.joomla.org/Standard_parameter_types表单字段-http://docs.joomla.org/Form_field

Lastly, it sounds like you would be better served creating a component instead of a module, unless you plan to display the database info you are pulling as part of another page that will be displaying the main content. 最后,听起来您最好还是创建一个组件而不是一个模块,除非您打算将要提取的数据库信息显示为另一个页面的一部分,该页面将显示主要内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM