{"id":2296,"date":"2020-06-16T11:59:16","date_gmt":"2020-06-16T16:59:16","guid":{"rendered":"https:\/\/xlinesoft.com\/blog\/?p=2296"},"modified":"2020-06-16T11:59:16","modified_gmt":"2020-06-16T16:59:16","slug":"context-help-in-your-web-applications","status":"publish","type":"post","link":"https:\/\/xlinesoft.com\/blog\/2020\/06\/16\/context-help-in-your-web-applications\/","title":{"rendered":"Context help in your web applications"},"content":{"rendered":"<p>This article explains how you can implement context help in your PHPRunner or ASPRunner.NET application. Maybe you need to display some hints for users or a link to a more detailed page in the manual. If you ever checked PHPRunner or ASPRunner.NET live demo you probably noticed how it looks there:<\/p>\n<p><a href=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/06\/scr.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/06\/scr-300x192.png\" alt=\"\" width=\"300\" height=\"192\" class=\"alignnone size-medium wp-image-2300\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/06\/scr-300x192.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/06\/scr-768x491.png 768w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/06\/scr-1024x655.png 1024w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/06\/scr.png 1493w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>We, of course, do not want to add those messages manually to every page. Instead, we will store all those messages in the database and display the relevant message based on what page we currently on. <\/p>\n<h4>1. Table to store messages<\/h4>\n<p>The following script is for MySQL:<\/p>\n<pre name=\"code\" class=\"sql:nocontrols\">\r\nCREATE TABLE `messages` (\r\n  `id` int(11) NOT NULL,\r\n  `pageName` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL,\r\n  `pageType` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL,\r\n  `value` text COLLATE utf8mb4_bin NOT NULL,\r\n  `project` int(11) NOT NULL\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;\r\n\r\nALTER TABLE `messages` ADD PRIMARY KEY (`id`);\r\nALTER TABLE `messages` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;\r\n<\/pre>\n<p>Here is how sample data in the <strong>messages<\/strong> table looks.<\/p>\n<p><a href=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/06\/scr2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/06\/scr2-300x146.png\" alt=\"\" width=\"300\" height=\"146\" class=\"alignnone size-medium wp-image-2304\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/06\/scr2-300x146.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/06\/scr2-768x374.png 768w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2020\/06\/scr2.png 946w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h4>2. AfterAppInit event.<\/h4>\n<pre name=\"code\" class=\"php:nocontrols\">\r\n$page = preg_replace('\/(\\\/|\\.php)\/i', '', substr($_SERVER[\"PHP_SELF\"], \r\n   strripos($_SERVER[\"PHP_SELF\"],\"\/\")) );\r\n$sym_pos = strripos($page,\"_\");\r\n$selectData[\"pageName\"] = $sym_pos?substr($page,0,$sym_pos):$page;\r\n$selectData[\"pageType\"] = $sym_pos?substr($page,$sym_pos+1):\"\";\r\n$selectData[\"project\"] = 1;\r\n$record = DB::Select(\"messages\", $selectData )->fetchAssoc();\r\n$_SESSION[\"messages\"] = \"\";\r\nif( $record ) $_SESSION[\"messages\"] = $record[\"value\"];\r\n<\/pre>\n<p>Here we parse the current page URL to find the table name and page type (&#8220;list&#8221;, &#8220;add&#8221; etc). We could have just stored the file name like &#8220;customers_list.php&#8221; but we&#8217;d like to use the same table for PHPRunner and ASPRunner.NET and ASPRunnerPro demos so we doing it this way. <\/p>\n<p>The <strong>project<\/strong> field is not required if you only have a single project. We have multiple live demos so the following tells that we are working with Liev Demo 1. <\/p>\n<pre name=\"code\" class=\"php:nocontrols\">\r\n$selectData[\"project\"] = 1;\r\n<\/pre>\n<p>Once the message is retrieved we store it in the session variable <strong>$_SESSION[&#8220;messages&#8221;]<\/strong> so we can later use it anywhere on the page. <\/p>\n<h4>3. Displaying the message<\/h4>\n<p>The easiest option is just to display it in the header. This is what we do in those live demos. Another option is to display it from the code snippet. <\/p>\n<pre name=\"code\" class=\"php:nocontrols\">\r\n&lt;?php \r\nprint $_SESSION[\"messages\"];\r\n?>\r\n<\/pre>\n<h4>4. Sample message HTML code<\/h4>\n<p>Here is HTML of the hint that is seen on the screenshot. <\/p>\n<pre name=\"code\" class=\"html:nocontrols\">\r\n&lt;DIV class=\"col-md-8 col-md-offset-2 alert alert-success info big-info\">\r\n&lt;DIV class=\"col-md-6\">\r\n&lt;ul>\r\n&lt;li>Preview with products&lt;\/li>\r\n&lt;li>Columns grid layout on the List page&lt;\/li>\r\n&lt;\/ul>\r\n&lt;\/DIV>\r\n&lt;DIV class=\"col-md-6\">\r\n&lt;ul>\r\n&lt;li>Custom template - without search panel&lt;\/li>\r\n&lt;li>Highlighting search results&lt;\/li>\r\n&lt;\/ul>\r\n&lt;\/DIV>\r\n&lt;\/DIV>\r\n<\/pre>\n<p>You can do something else, i.e. display a link to the page in the manual. <\/p>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article explains how you can implement context help in your PHPRunner or ASPRunner.NET application. Maybe you need to display some hints for users or a link to a more detailed page in the manual. If you ever checked PHPRunner or ASPRunner.NET live demo you probably noticed how it looks there: We, of course, do not want to add those messages manually to every page. Instead, we will store all those messages in the database and display the relevant message based on what page we&#8230;<span class=\"clearfix clearfix-post\"><\/span><a href=\"https:\/\/xlinesoft.com\/blog\/2020\/06\/16\/context-help-in-your-web-applications\/\" class=\"more-link\">Continue Reading <span class=\"screen-reader-text\">&#8220;Context help in your web applications&#8221;<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,1],"tags":[],"_links":{"self":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/2296"}],"collection":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/comments?post=2296"}],"version-history":[{"count":6,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/2296\/revisions"}],"predecessor-version":[{"id":2305,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/2296\/revisions\/2305"}],"wp:attachment":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/media?parent=2296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/categories?post=2296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/tags?post=2296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}